The goal of this script is to grant the destination user all the missing memberships when compared to the source user. Any missing memberships will be added by this script while outputting the changes to the console.

This script compares the group membership of two AD users, user1 and user2. User1 in this case is the source user, the script will list the group membership of yser1 then compares this to the group memberships of user2. If user2 is not a member of any of the group that user1 is a member of then the script will add user2 to all those groups while displaying the groups it will be added to. If user2 is already a member of all the groups that user1 is a member of no action will be taken. Also when user2 is a member of more groups than user1 no action will be taken either.

Version 1.0 - Updated on 26-03-2012: Changed error handling


Version 1.1 - Updated on 07-05-2012


Version 1.2 - Updated on 12-01-2016



Script that compares group membership of source users and destination user and adds destination user to source user group  
This script compares the group membership of $sourceacc and $destacc, based on the membership of the source account the destination account is also to these groups. Script outputs actions taken to the prompt. The script can also be run without any parameters then the script will prompt for both usernames. 
.PARAMETER Sourceacc 
User of which group membership is read 
User that becomes member of all the groups that Sourceacc is member of 
.PARAMETER MatchGroup 
Supports regular expressions, uses the -match operator to make a select a subset of source user groups to copy to the destination user 
.PARAMETER Noconfirm 
No user input is required and the script runs automatically 
Name: Compare-ADuserAddGroup.ps1 
Author: Jaap Brasser 
Version: 1.2.0 
DateCreated: 2012-03-14 
DateUpdated: 2016-01-12 
.\Compare-ADuserAddGroup.ps1 testuserabc123 testuserabc456 
This command will add testuserabc456 to all groups that testuserabc123 is a memberof with the exception of all groups testuserabc456 is already a member of. 
.\Compare-ADuserAddGroup.ps1 -SourceAcc testuserabc123 -DestAcc testuserabc456 -MatchGroup 'FS_' 
This command will add testuserabc456 to the groups that contain the FS_ string that testuserabc123 is a memberof with the exception of all groups testuserabc456 is already a member of.