Your Exchange Server infrastructure needs to stay up to date because of vulnerabilities, new features,…
Copy members from one AD group to another
AD groups are great for managing users, computers, groups, and other AD objects. This time you created a new AD group in Active Directory, and you want to copy members from one AD group to the new group. How to copy members from security group to distribution groups or the other way around? This article will teach you how to copy members from one AD group to another with PowerShell.
Table of contents
Information
If you have a couple of members, you can search and select them in Active Directory Users and Computers (ADUC). But what if you have many members, let’s say a thousand. Or, what if you want to be precise with copying members.
By reading another group from a list and adding them to another group is not bulletproof. You can miss a member, and that’s not what you want. That’s when you want to use PowerShell.
In our example, we like to copy the users from the AD group SG_Azure_A to another AD group SG_Azure_B.
- Source: SG_Azure_A
- Target: SG_Azure_B
AD members that we can copy
To copy members from one AD group to another will work for all group scopes and group types:
- Group scope: Domain local / Global / Universal
- Group type: Security / Distribution
Copy members will work criss-cross between the AD groups. For example, you have members in a Global Security, and you want to copy members to another Universal Distribution group, it works excellent.
In our example, we will copy members from a Universal Security group to another Universal Security group.
Good to know is that it will copy all Object Types from the member’s group.
Copy members from one AD group to another with PowerShell
Run PowerShell as administrator. List the members in the source AD group. Make use of Get-AdGroupMember cmdlet.
PS C:\> Get-ADGroupMember -Identity "SG_Azure_A" | Select-Object Name | Sort-Object Name
Name
----
Ali Tajran
Amanda Morgan
Amelia Nash
Benetiz Anees
Boris Campbell
Christopher Payne
Grace Rees
Irene Springer
Jasmina Teneres
Jonathan Fisher
Kylie Davidson
Leonard Clark
Madeleine Fisher
Mary Walsh
Max Fraser
Melanie Scott
Nicholas Murray
Piers Bower
Richard Grant
Ruth Dickens
Sebastian Nolan
Zoë Rees
Get the target group and use the ForEach-Object cmdlet to add the members to the source AD group.
PS C:\> Get-ADGroupMember -Identity "SG_Azure_A" | ForEach-Object {Add-ADGroupMember -Identity "SG_Azure_B" -Members $_.distinguishedName}
Do you want to copy members from one distribution group to another AD group? The only thing you need to change is the source and target AD groups.
Verify target AD group members
With the previous cmdlet, we did copy members from one AD group to another. It’s good to list the target AD group and verify that the copy did go successfully.
PS C:\> Get-ADGroupMember -Identity "SG_Azure_B" | Select-Object Name | Sort-Object Name
Name
----
Ali Tajran
Amanda Morgan
Amelia Nash
Benetiz Anees
Boris Campbell
Christopher Payne
Grace Rees
Irene Springer
Jasmina Teneres
Jonathan Fisher
Kylie Davidson
Leonard Clark
Madeleine Fisher
Mary Walsh
Max Fraser
Melanie Scott
Nicholas Murray
Piers Bower
Richard Grant
Ruth Dickens
Sebastian Nolan
Zoë Rees
Verify the target AD group in ADUC.
We did successfully copy AD members from one AD group to another AD group. In our example, we did copy the members from a Universal Security group to another Universal Security group that is empty.
Read more: Convert Global to Universal Security Group with PowerShell »
Conclusion
You learned how to copy members from one AD group to another with PowerShell. If you have a couple of members, you can use Active Directory Users and Computers and add members to the AD group. If you have many members and want to speed up your work, your best way is PowerShell.
Did you enjoy this article? You may also like List all users in a Security Group through PowerShell. Don’t forget to follow us and share this article.
Thank you for this such well explained and written text.