Copy AD group members

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.

2 thoughts on “Copy AD group members

  1. FYI – In the downloaded script you have left “Remote Desktop Services Users” hard coded in, rather than the variable for the destination group.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s