Powershell - Compare Active Directory Groups
Here is a Powershell script that compares two Active Directory groups, and determines the differences between the account membership of them.
$DN1 = "CN=Group1,OU=Groups,OU=Accounts,DC=subdomain,DC=mydomain,DC=local"
$DN2 = "CN=Group2,OU=Groups,OU=Accounts,DC=subdomain,DC=mydomain,DC=local"
$Group1 = [adsi]"LDAP://$DN1"
$Group2 = [adsi]"LDAP://$DN2"
ForEach ($User in $Group1.member)
{
if ($Group2.member -contains $User)
{
Write-Host "$User belongs to $($Group2.cn)"
}
else
{
Write-Host "$User does not belong to $($Group2.cn)"
}
}-Trevor Sullivan