≡ Menu

Powershell: Get Active Directory Sites and subnets list

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


$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            



{ 6 comments… add one }
  • Bodybuilding directory March 14, 2012, 7:50 am

    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.

  • noeo November 2, 2012, 5:03 am

    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.


    • Sitaram Pamarthi November 3, 2012, 9:04 pm

      Hi Noeo, try the following to redirect the output to a CSV file.

      Get-ADSites.ps1 | Export-CSV c:\temp\sites.csv

  • Sumit February 18, 2013, 12:19 am


    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

  • Annie August 18, 2015, 12:57 pm

    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 !!

Leave a Comment