If you like me sometimes need to copy users and/or computers from one group to another this script will help you.
Just save the script (to for example “CopyGroupMembers.ps1”) and run it like “CopyGroupMembers.ps1 -FromGroup <groupname> -ToGroup <groupname>” by using the parameters to copy the group members.
To get the script to work you need the Active Directory PowerShell module installed where you run the script and security rights to copy the members.
$FromGroupMembers = Get-ADGroupMember -Identity $FromGroup
Foreach ($Member in $FromGroupMembers.distinguishedName)
Add-ADGroupMember -Identity $ToGroup -Members $Member
Write-Host “Added member: $Member to group $ToGroup“