This post talks about querying Active Directory Sites and subnets information from AD using Powershell. This script is helpful when you want to know subnets mapping to given site and servers lying in a site. This scrip doesn’t need much explanation since it is looking very straight forward. If you defer with me, please comment what part of script you want to understand. Also feel free to post if you would like to query any other information related to sites and services. Happy to help.
Code: Get-ADSites.ps1
[cmdletbinding()] param() $Sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites foreach ($Site in $Sites) { $obj = New-Object -Type PSObject -Property ( @{ "SiteName" = $site.Name; "SubNets" = $site.Subnets; "Servers" = $Site.Servers } ) $Obj }
Output
Comments on this entry are closed.
Hello, Neat post. There’s a problem together with your web site in web explorer, would check this? IE nonetheless is the market leader and a large part of other folks will miss your wonderful writing due to this problem.
Is there any way to export this script to csv file? Where do I place it in the script? Since my domain has few DCs within a site and multiple IP Subnets with the site, it tends to chop a lot of information from the powershell window screen.
thanks
Hi Noeo, try the following to redirect the output to a CSV file.
Get-ADSites.ps1 | Export-CSV c:\temp\sites.csv
Hello,
When I am exporting output in CSV it only gives me first subnet and then its giving me output like “12.12.34….” etc . I want full out put of all the subnets for each site
Hi Sumit,
See this forum post
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/c0e203ed-e146-4d0f-9c57-1ec263284ace/exporting-active-directory-sites-and-services-information-to-csv-file
It does the tric
Hello,
This is great script , thanks to you.
I also ran this script in my environment and it has given me output. We have 10 sites and few Domain controllers at each site. The script given correct information of all site with servers and subnets they belongs to, other then of one site that actually contains 4 DCs but blank in script output.
Can you tell me what may be the reason to that? My ADSS shows me that site with proper NTDS configuration.
Thanks !!