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

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 )

Google photo

You are commenting using your Google 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