获取当前用户上下文 [英] get Current user context

查看:89
本文介绍了获取当前用户上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从不同位置(c#应用程序,webservice ...)运行powershellscript时遇到问题. 我认为这是一个用户上下文问题,所以现在我试图找出在哪个用户上下文下运行Powershell脚本.

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.

是否有可能记录powershellscript的当前用户上下文?

推荐答案

如果您需要了解实际用户:

If you need to know the actual user:

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

使用:

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

了解UserPrincipal的可用属性/方法.

to know available properties/methods of UserPrincipal.

这篇关于获取当前用户上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆