Created
February 10, 2021 13:23
-
-
Save kneradovsky/6282ecf61e1e44e7e236f28048596cbe to your computer and use it in GitHub Desktop.
Powershell script to add multiple users to the Administators and Remote Desktop Users group to multiple the remote servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$servers = "server1","server2" | |
$users = "user1","user2","user3" | |
$domain= "domain" | |
$admin = "admin" | |
$admin_user = Get-Credential -Credential "$domain\$admin" | |
ForEach ($server in $servers) { | |
Write-Host $server; | |
$admin_grp = [ADSI]::new("WinNT://$server/Administrators,group",$admin_user.UserName,$admin_user.GetNetworkCredential().Password); | |
$rdp_grp = [ADSI]::new("WinNT://$server/Remote Desktop Users,group",$admin_user.UserName,$admin_user.GetNetworkCredential().Password); | |
foreach( $user in $users) { | |
Write-Host $user; | |
$aduser = ([ADSI]"WinNT://$domain/$user,user").Path; | |
$admin_grp.Add($aduser); | |
$rdp_grp.Add($aduser); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment