Life of a techno-guru
Wednesday, February 11, 2009
  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
 
Comments:
How would you output the results from this script? I have tried the standard | export-csv -path filename.csv and even tried > file.txt to output to a standard text file. The file gets created but with no data. What am I doing wrong here?
 
Post a Comment



<< Home
My life of learning various things about technology including network administration, development, and 3D design

Name:
Location: Chicago, Illinois, United States
ARCHIVES
January 2006 / February 2006 / March 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / August 2007 / December 2007 / January 2008 / March 2008 / April 2008 / June 2008 / July 2008 / September 2008 / December 2008 / January 2009 / February 2009 / March 2009 / May 2009 /


Powered by Blogger