PowerShell - Add a user to the administrators group using the adsi command

by
Jeremy Canfield |
Updated: August 02 2022
| PowerShell articles
This command can be used to add a local user account to a group (such as administrators) using PowerShell.
- Replace ComputerName with the hostname of the computer
- Replace username with the username of the account to add to the group
([adsi]"WinNT://ComputerName/administrators,group").Add("WinNT://ComputerName/username,user")
If on a domain, use the DomainName instead of the ComputerName.
([adsi]"WinNT://ComputerName/administrators,group").Add("WinNT://DomainName/username,user")
This command can be used to view the members of the group.
gwmi -query "select PartComponent, __Server from Win32_GroupUser where GroupComponent=`"Win32_Group.Domain='$env:Computername',Name='$localgroup'`"" |
% { [WMI] $_.PartComponent } |
ft -a Domain, Name, FullName, Description
Did you find this article helpful?
If so, consider buying me a coffee over at