如何在脚本中判断PowerShell是否以管理员权限运行?
我需要知道,因为我正在尝试运行需要打开受保护端口的功能的程序。
[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
分解这是做什么的:
[bool]
-将最终结果转换为bool
。[System.Security.Principal.WindowsIdentity]::GetCurrent()
-检索WindowsIdentity
当前正在运行的用户的。(...).groups
-访问groups
身份的属性,以查找该身份所属的用户组。-match "S-1-5-32-544"
检查以查看是否groups
包含管理员组的SID,该标识仅在使用“以管理员身份运行”时包含。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句