Get current user context

I am having problems running powershellscript from different places (C # application, webservice ...). I think this is a user context problem, so now I'm trying to figure out under which userhell script is running.

Is it possible to register the current custom powershellscript text?

+6
source share
2 answers

If you need to know the actual user:

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

Using:

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

to find out the available properties / methods of UserPrincipal .

+4
source

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

 [Security.Principal.WindowsIdentity]::GetCurrent() 
+6
source

Source: https://habr.com/ru/post/918537/


All Articles