Add User To The Local Administrators Group On Multiple Computers Using PowerShell

 

To achieve the objective I’m using the Invoke-Command PowerShell cmdlet which allows us to run PowerShell commands to local or remote computers.

In the example below, I’ll add my User ABC to the local Administrators group on two Server (serv1, serv2)

Invoke-Command -ComputerName Serv1, Serv2 -ScriptBlock {add-LocalGroupMember -Group "Remote Desktop Users" -Member ABC }
 There is another everyone's favorite way here along with input file and result comment:

$Computerlist = get-content "C:\temp\servers.txt"


foreach ($computername in $computerlist) {
Invoke-Command -ComputerName $computername -ScriptBlock {add-LocalGroupMember -Group "Administrators" -Member GIN }
Write-host "ABC User added in $computername"
}
 
 

Comments

Popular posts from this blog

Changes in Windows 2008 Active Directory

Windows Server Support Interview Questions and Answers (L1)

How to Write a Letter Requesting Sponsorship