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
If you like this script and want to support me so I can create and share more scripts, please consider donating to me through PayPal.
FYI – In the downloaded script you have left “Remote Desktop Services Users” hard coded in, rather than the variable for the destination group.
LikeLiked by 1 person
Thank you very much. I had missed that. It has been replaced.
LikeLike