List all Sites and Subnets in AD

This script will export a list of all Site and Subnets and the domain controllers in them.

[cmdletbinding()]
 param()

$Sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
$obj = @()
foreach ($Site in $Sites) {

  $obj += New-Object -Type PSObject -Property (
   @{
    "SiteName"  = $site.Name
    "SubNets"  = $site.Subnets  -Join ";"
    "Servers"  = $Site.Servers  -Join ";"
   }
  )
 }
$obj | Export-Csv 'C:\sites.csv' -NoType
Facebooktwittergoogle_pluslinkedinby feather

Leave a Reply

Your email address will not be published. Required fields are marked *