如何使用Powershell在PC上让自己成为管理员?
例外:
Cannot find group name + $AdminGroup.Add($InUser.Path) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException + FullyQualifiedErrorId : CatchFromBaseGetMember
$User = $env:USERNAME
$HostName = $env:COMPUTERNAME
$DomainName = "xxxx"
$AdminGroup = [ADSI]"WinNT://$HostName/administrators,group"
$InUser = [ADSI]"WinNT://$DomainName/$User,user"
$AdminGroup.Add($InUser.Path)
答案 0 :(得分:1)
您可以通过向BUILTIN \ Administrators组SID查询Win32_Group
来找到组名:
$AdministratorsGroupName = (Get-CimInstance -ClassName Win32_Group -Filter 'SID = "S-1-5-32-544"').Name
# ...
$AdminGroup = [adsi]"WinNT://$HostName/$AdministratorsGroupName,group"