Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get Current user context

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?

like image 910
HW90 Avatar asked Jun 20 '12 08:06

HW90


2 Answers

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

[Security.Principal.WindowsIdentity]::GetCurrent()
like image 58
Stefan Avatar answered Nov 16 '22 02:11

Stefan


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.

like image 36
CB. Avatar answered Nov 16 '22 03:11

CB.