FreeKB - PowerShell adsi command (add a user to the administrators group)
PowerShell - adsi command (add a user to the administrators group)

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |