How to add the user to the local Administrators group using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To add the AD user or the local user to the local Administrators group using PowerShell, we need to use the Add-LocalGroupMember command.

To add the local user to the local Administrators group,

Add-LocalGroupMember -Group Administrators -Member TestUser -Verbose

The above command will add TestUser to the local Administrators group. You can provide any local group name there and any local user name instead of TestUser

You can also add the Active Directory domain user to the Local Administrators group by providing the domain name if the computer is in the same domain.

For example, we will add the Beta user from the AutomationLab domain as shown below.

Add-LocalGroupMember -Group Administrators -Member AutomationLab\Beta

You can provide the multiple members separated by comma (,) but only one local group is supported.

Add-LocalGroupMember -Group Administrators -Member TestUser, Testuser2 -Verbose

To add the local user or the AD user to the remote computer, use Invoke-Command.

Invoke-Command -ComputerName Computer1, Computer2 -ScriptBlock{
   Add-LocalGroupMember -Group Administrators -Member TestUser1, TestUser2
Updated on 17-May-2021 12:20:48