7

I've got problems with running a powershellscript from different locations (c# application, webservice...). I think it is a user context problem, so now I'm trying to find out under which user context powershell script is running.

Is there any possibility log the current usercontext of the powershellscript?

4

2 回答 2

11

You could use the WindowsIdentity class to get the current thread user:

[Security.Principal.WindowsIdentity]::GetCurrent()
于 2012-06-20T08:43:15.067 回答
5

If you need to know the actual user:

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

Use:

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

to know available properties/methods of UserPrincipal.

于 2012-06-20T08:44:15.657 回答