I needed to copy AD group members to another AD group, if they didn’t already exist in the target group.
This is very plain and simple script you can run the script and add -SourceGroup "group name" -DestinationGroup "destination group"
, or omit those and the script will ask you for it (since they are mandatory).
The script will get all members of both groups.
$SourceGroupMembers = Get-ADGroupMember -Identity "$SourceGroup"
$DestinationGroupMembers = Get-ADGroupMember -Identity "$DestinationGroup"
It will loop through all members in the source group and check if they exists in the destination group.
If($DestinationGroupMembers.SamAccountName -match $SourceGroupMember.SamAccountName)
If they don’t exist, the script will add the member to the group. It will create a log file and output to the screen when it adds a users to the destination group.
Add-ADGroupMember -Identity "Remote Desktop Services Users" -Members $SourceGroupMember.SamAccountName
You can find the script here