Skip to content

Instantly share code, notes, and snippets.

@truekonrads
Created July 3, 2012 11:43
Show Gist options
  • Save truekonrads/3039251 to your computer and use it in GitHub Desktop.
Save truekonrads/3039251 to your computer and use it in GitHub Desktop.
Counts the number of sites in each AD site link
$dEntry = New-Object DirectoryServices.DirectoryEntry("LDAP://xyz.com/cn=sites,cn=configuration,dc=xyz,dc=com","user1","Pass1");
$searcher=New-Object DirectoryServices.DirectorySearcher($dEntry);
$searcher.Filter="(objectClass=siteLink)";
$searcher.PropertiesToLoad.Add("siteList");
$searcher.PropertiesToLoad.Add("cost");
$searcher.PropertiesToLoad.Add("replInterval");
$searcher.PropertiesToLoad.Add("cn");
$searcher.FindAll() |%{
$count=$_.Properties.sitelist.Count;
$p=@{"cn"=[string]$_.Properties.cn; "sites"=$count;};
if ($count>2) {
$p["mesh"]=$count;
}else{
$p["mesh"]=$count*$count;
}
New-Object psobject -Property $p
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment