【发布时间】:2012-06-22 08:40:06
【问题描述】:
我在从不同位置(c# 应用程序、webservice...)运行 powershellscript 时遇到问题。 我认为这是一个用户上下文问题,所以现在我试图找出在哪个用户上下文下运行 powershell 脚本。
是否有可能记录 powershellscript 的当前用户上下文?
【问题讨论】:
标签: powershell powershell-2.0 impersonation
我在从不同位置(c# 应用程序、webservice...)运行 powershellscript 时遇到问题。 我认为这是一个用户上下文问题,所以现在我试图找出在哪个用户上下文下运行 powershell 脚本。
是否有可能记录 powershellscript 的当前用户上下文?
【问题讨论】:
标签: powershell powershell-2.0 impersonation
您可以使用WindowsIdentity class 获取当前线程用户:
[Security.Principal.WindowsIdentity]::GetCurrent()
【讨论】:
[Security.Principal.WindowsIdentity]::GetCurrent().Name 将为您提供特定用户
whoami。这也将为您提供当前上下文用户
如果您需要了解实际用户:
[reflection.assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement")
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current
用途:
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current | gm
了解UserPrincipal 的可用属性/方法。
【讨论】: