Powershell 获取当前用户上下文
我在从不同位置(c#应用程序、Web服务…)运行powershellscript时遇到问题。 我认为这是一个用户上下文问题,所以现在我试图找出在哪个用户上下文下运行powershell脚本 是否有可能记录powershellscript的当前用户上下文?您可以使用获取当前线程用户:Powershell 获取当前用户上下文,powershell,powershell-2.0,impersonation,Powershell,Powershell 2.0,Impersonation,我在从不同位置(c#应用程序、Web服务…)运行powershellscript时遇到问题。 我认为这是一个用户上下文问题,所以现在我试图找出在哪个用户上下文下运行powershell脚本 是否有可能记录powershellscript的当前用户上下文?您可以使用获取当前线程用户: [Security.Principal.WindowsIdentity]::GetCurrent() 如果您需要了解实际用户: [reflection.assembly]::LoadWithPartialName(
[Security.Principal.WindowsIdentity]::GetCurrent()
如果您需要了解实际用户:
[reflection.assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement")
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current
使用:
了解UserPrincipal
的可用属性/方法
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current | gm