A good old PowerShell will help you in case you wish to collect AD site information such as Active Directory site location, site options configured, ISTG assigned to the site, Site links and bridgehead servers. Below PowerShell Script uses New-Object function to connect to Directory Context and then get all Active Directory sites. All Active Directory sites are stored in a variable. Script uses ForEach loop to traverse through each site stored in the variable and then append the site information in a CSV file.
$ReportFile = "C:TempADSiteInfo.CSV" Remove-item $ReportFile -ErrorAction SilentlyContinue $ThisString="AD Site,Location,Site Option,Current ISTG,Subnets,Servers,In Site Links,Bridgehead Servers" Add-Content "$ReportFile" $ThisString $CurForestName = "Netwrix.com" $a = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext("Forest", $CurForestName) [array]$ADSites=[System.DirectoryServices.ActiveDirectory.Forest]::GetForest($a).sites $ADSites ForEach ($Site in $ADSites) { $SiteName = $Site.Name $SiteLocation = $site.Location $SiteOptions = $Site.Options $SiteISTG = $Site.InterSiteTopologyGenerator [array] $SiteServers = $Site.Servers.Count [array] $SiteSubnets = $Site.Subnets.Count [array] $SiteLinks = $Site.SiteLinks.Count [array] $SiteBH = $Site.BridgeheadServers.Count $FinalVal=$SiteName+","+'"'+$SiteLocation+'"'+","+'"'+$SiteOptions+'"'+","+$SiteISTG+","+$SiteSubnets+","+$SiteServers+","+$SiteLinks+","+$SiteBH Add-Content "$ReportFile" $FinalVal }
Once above PowerShell script has been executed, you will have information for each Active Directory site stored in “C:TempADSiteInfo.CSV” file. Note that by default script connects to the current Active Directory Forest. In case you wish to change the report file location, please modify $ReportFile variable.
Need more PowerShell scripts for Active Directory? Find all the top wanted PowerShell commands for Active Directory in one blog post.
Thank you for the script, having a problem with the array:
$a = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext(“Forest”, $CurForestName)
[array]$ADSites=[System.DirectoryServices.ActiveDirectory.Forest]::GetForest($a).sites
$ADSites
Exception calling “GetForest” with “1” argument(s): “The specified forest does not exist or cannot be contacted.”
At line:3 char:1
+ [array]$ADSites=[System.DirectoryServices.ActiveDirectory.Forest]::Ge …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ActiveDirectoryObjectNotFoundException
IsPublic IsSerial Name BaseType
——– ——– —- ——–
True False Forest System.Object
Any assistance would be greatly appreciated
Have you changed $CurForestName = “NetWrix.com” parameter?
Hi Yan, I did but the wrong domain name in, senior moment. Works perfectly with the right domain id
Norm
Hi Yan;
Did change it but to the wrong id, with the right id it works perfectly. Thank you for responding
One minor error. Line 14 – change $SiteOption to $SiteOptions
shux, thought I would be the only one to catch that! 😀
Excellent…works like a charm!
You’re welcome, Peter!