Вы можете попробовать следующую функцию, которая для данного имени пользователя:
- пытается найти базовый идентификатор (учетная запись пользователя NT) в том же контексте, что и вызывающий пользователь (домен противместный);имя пользователя может быть указано в нескольких форматах, в том числе в формате NTLM (
<domain>\<username>
). - , а затем проверяет эту идентичность на (статическое) членство во встроенном local
Administrators
группа.
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'
}