Windows 有没有办法通过PowerShell在本地服务器上检查任意安全主体的管理权限?
web上的许多示例展示了使用Windows 有没有办法通过PowerShell在本地服务器上检查任意安全主体的管理权限?,windows,powershell,privileges,Windows,Powershell,Privileges,web上的许多示例展示了使用 [Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent() 在特定服务器上运行命令时,是否有类似的方法来检查“当前”标识,而不是任何标识(例如,从Get-ACLcmdlet检索的本地或域) 我检查了,但找不到一种方法(仅当您使用带有UPN参数的构造函数时,这不适合我的情况)。如果有任何提示,我将不胜感激。您可以尝试以下功能,对于给定的用户名
[Security.Principal.WindowsPrincipal]
[Security.Principal.WindowsIdentity]::GetCurrent()
在特定服务器上运行命令时,是否有类似的方法来检查“当前”标识,而不是任何标识(例如,从Get-ACL
cmdlet检索的本地或域)
我检查了,但找不到一种方法(仅当您使用带有UPN参数的构造函数时,这不适合我的情况)。如果有任何提示,我将不胜感激。您可以尝试以下功能,对于给定的用户名:
- 尝试在与调用用户相同的上下文中查找基础标识(NT用户帐户)(域与本地);用户名可以多种格式指定,其中包括NTLM格式(
)\
- 然后在内置的本地
组中测试该身份的(静态)成员身份Administrators
为什么UPN不适合您?您计划如何指定用户名?我希望它也适合本地用户。作为“服务器\用户名”或“域\用户名”。您可以对域用户使用UPN而不会出现问题(如user@domain)但不适合本地人。您可以尝试此处所述的另一种方法检查组mermbership是一种稍微不同的方法,我已经使用WMI、递归方法为此编写了一个函数,但是使用
IsInRole:Administrator
的方法似乎开销较小,所以我希望使用那种“懒惰”的方法。。。来自System.DirectoryServices.AccountManagement
命名空间的那些类可能很有用,但我目前看不到与WMI+GetRelated()
方法相比的好处,甚至更多-据我所知,如果我必须同时检查本地和域用户,我必须创建和操作两个上下文(机器+域)。无论如何,谢谢你的提示。@Max:我的理解是,如果你想检查其他用户,在没有与具体流程相关联的帐户令牌的情况下,检查组成员身份是你所能做的一切。有效的管理权——与潜在的管理权相反,通过集团成员资格——只能针对实际流程进行检查。(顺便说一句:扩展函数以查看域和机器上下文将很容易。)我明白了。顺便说一句,您能否指出如何为特定用户实施有效的NTFS ACL访问检查?这超出了我的问题范围,但与我正在尝试做的事情有关。@Max:请参阅及其注释-看起来您可能需要通过P/Invoke自己调用Windows API。
function Test-LocalAdminGroupMembership {
param([string] $user)
# Load the required assembly (a no-op if already loaded).
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
# Obtain the specified user as a UserPrincipal instance.
$up = try {
if (-not $user) { # default to current user
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current
} else {
[System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity(
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current.Context,
$user
)
}
} catch {
Throw
}
# See if the well-known SID of the local Administrators group
# is among the SIDs of the groups that the user is a member of (PSv3+ syntax).
$up.GetGroups().SID.Value -contains 'S-1-5-32-544'
}