Sunday 10 July 2016

Export Site Name and Subnet from AD Sites & Services using Powershell

Below Powershell command will help you to get the Site name and associated Subnets for that particular sites in Active Directory.


$sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites

$sitesubnets = @()

foreach ($site in $sites)
{
foreach ($subnet in $site.subnets){
  $temp = New-Object PSCustomObject -Property @{
  'Site' = $site.Name
  'Subnet' = $subnet; }
   $sitesubnets += $temp
}
}

$sitesubnets | Export-CSV subnet.csv

No comments:

Post a Comment