Skip to content

Instantly share code, notes, and snippets.

@kneradovsky
Created February 10, 2021 13:23
Show Gist options
  • Save kneradovsky/6282ecf61e1e44e7e236f28048596cbe to your computer and use it in GitHub Desktop.
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
$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