get Current user context get Current user context powershell powershell

get Current user context


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

[Security.Principal.WindowsIdentity]::GetCurrent()


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.