2012-06-20 93 views
6

我遇到了從不同位置運行powershellscript的問題(c#應用程序,webservice ...)。 我認爲這是一個用戶上下文問題,所以現在我試圖找出在哪個用戶上下文powershell腳本運行。獲取當前用戶上下文

有沒有可能記錄powershellscript的當前usercontext?

回答

4

如果您需要了解實際的用戶:

[reflection.assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement") 
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current 

用途:

[System.DirectoryServices.AccountManagement.UserPrincipal]::Current | gm 

到了解UserPrincipal的可用屬性/方法。