get Current user context

给你一囗甜甜゛ 提交于 2019-12-19 03:06:09

问题


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?


回答1:


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.




回答2:


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

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


来源:https://stackoverflow.com/questions/11115686/get-current-user-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!