Collaboration-2-Go


Lösungen und Software-Entwicklung im Collaboration Umfeld, insbesondere Microsoft SharePoint, Microsoft Exchange und Microsoft Office.

Support


Mobil: +49 (152) 53 97 78 79
Mail: service@collaboration-2-go.de
Weitere Kontaktmöglichkeiten: Kontaktseite
Dekoration: Köln



Remove duplicate Active Directory Group Memberships
Created: 10.12.2014
Categories: PowerShell

Once I had to remove all users in an Active Directory group in case they are also member of a second group.


# if I have to talk to a different but truested domain
$dc = "my_domain_controller"

# my groups
$group1 = "my_first_group"
$group2 = "my_second_group"

diff (Get-ADGroupMember -Identity $group1 -Server $dc) (Get-ADGroupMember -Identity $group2 -Server $dc) -Property 'distinguishedName' -IncludeEqual | ?{ $_.sideIndicator -eq "==" } | foreach-object { write-host $_.distinguishedName ; Remove-ADGroupMember -Identity $group1 -Server $dc -Members $_.distinguishedName -Confirm:$false }

    

Send us a Comment!