get Current user context

HW90 picture HW90 · Jun 20, 2012 · Viewed 12.4k times · Source

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?

Answer

Stefan picture Stefan · Jun 20, 2012

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

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