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

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 3a57f4 in the box below so that we can be sure you are a human.