Replicate all group members from Group A to Group B in Powershell
This is going to be a very quick article that will show you how to simply replicate all members from a group over to another group with the AD powershell module.
There are mainly two different goals:
- You want to replicate all group members from Group A to Group B in Powershell, as they are.
- You want to replicate all users that are in Group A recursively to Group B.
Case 1
Get-ADGroupMember "Group A" | % {Add-ADGroupMember "Group B" $_}
Simple enough, this will grab every member as it is (either a user, a group or any other object) and add it to Group B.
Case 2
Get-ADGroupMember "Group A" -Recursive | % {Add-ADGroupMember "Group B" $_}
The difference between case 1 and 2 is -Recursive. This will grab all members including members of other groups. For instance if Group A had 3 members, 2 user objects and a group called “Group A1” which then contained 3 users, you will see that Group B will contain just the 5 users and not the groups.