top of page

PowerShell - List all Subnets with Site Name in Forest

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 10, 2022
  • 1 min read

Save as a .ps1. run and exports all Subnets in Forest and Site Names to user profile folder as AD-Subnets.csv

## Get a list of all domain controllers in the forest

$DcList = (Get-ADForest).Domains | ForEach { Get-ADDomainController -Discover -DomainName $_ } | ForEach { Get-ADDomainController -Server $_.Name -filter * } | Select Site, Name, Domain


## Get all replication subnets from Sites & Services

$Subnets = Get-ADReplicationSubnet -filter * -Properties * | Select Name, Site, Location, Description


## Create an empty array to build the subnet list

$ResultsArray = @()


## Loop through all subnets and build the list

ForEach ($Subnet in $Subnets) {


$SiteName = ""

If ($Subnet.Site -ne $null) { $SiteName = $Subnet.Site.Split(',')[0].Trim('CN=') }


$DcInSite = $False

If ($DcList.Site -Contains $SiteName) { $DcInSite = $True }


$RA = New-Object PSObject

$RA | Add-Member -type NoteProperty -name "Subnet" -Value $Subnet.Name

$RA | Add-Member -type NoteProperty -name "SiteName" -Value $SiteName

$RA | Add-Member -type NoteProperty -name "DcInSite" -Value $DcInSite

$RA | Add-Member -type NoteProperty -name "SiteLoc" -Value $Subnet.Location

$RA | Add-Member -type NoteProperty -name "SiteDesc" -Value $Subnet.Description


$ResultsArray += $RA


}


## Export the array as a CSV file

$ResultsArray | Sort Subnet | Export-Csv .\AD-Subnets.csv -nti



 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page