Techibee.com

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

[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

Exit mobile version