Add Users to a Active Directory Group with Powershell and remove them from the old group



Moving a big amount of Users from one AD Group to another can be easily done with Powershell. 

At first create a .txt file where you can copy all of your Users you want to remove from an old AD Group and add them to a new one. I called this "userslist.exe" and placed it under C:\Users\etc

Things you need to replace are marked in RED



$users = Get-Content C:\YOUR_PATH\userslist.txt
$userId = @()

foreach ($user in $users) {
$userId += Get-ADUser $user
}

#AD Group Binding
$oldGroup = Get-ADGroup 'YOUR_OLD_GROUP_NAME'
$newGroup = Get-ADGroup ' YOUR_NEW_GROUP_NAME'

foreach ($user in $userId) {

   Remove-ADGroupMember -Identity $oldGroup -Members $user -Confirm:$false
   Add-ADGroupMember -Identity $newGroup -Members $user -Confirm:$false
   
 } 

Comments

Popular posts from this blog

Export a list of all XenApp 7.x published applications via Powershell

Implementing Single Sign On with NetScaler and Kerberos Constrained Delegation (KCD)

How to: Create a Client Certificate for LDAPS with OpenSSL