Avatar of fireguy1125

asked on 

Synchronize/Mirror AD Security Group Membership Script

I need to synchronize group membership for several AD security groups.  I was able to put together a script that will add any new group members from the source security group to the destination security group, however, I also need to be able to have the script remove members from the destination security group, when they are removed from the source.  How can I modify this script to achieve this?

$source = Get-ADGroupMember -Identity SourceADGroup
foreach ($user in $source) { 
    Add-ADGroupMember -Identity DestADGroup -Members $user.distinguishedname 

Open in new window

Thank you in advance.
Active DirectoryPowershell

Avatar of undefined
Last Comment

8/22/2022 - Mon