O R G A N I C / F E R T I L I Z E R: list active directory subnets with powershell

Sep 24, 2009

list active directory subnets with powershell

Windows PowerShell

sometimes it’s fun to do things the long way (not) and then do the equivalent in a shortcut fashion.

these are the steps i used to retrieve subnets from active directory.


first of all, let’s grab the forest.

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


now, we can get the list of sites names.

$myForest.Sites | Select-Object name


if we see a site name that we like, we can retrieve just that site name and the subnets associated with it.

$myForest.Sites | Where-Object { $_.Name -eq 'myCity' } | Select-Object Subnets


well, that’s probably not what you wanted unless you have such few subnets you can see the whole thing.  let’s pass that through the ExpandProperty feature of select-object.

$myForest.Sites | Where-Object { $_.Name -eq 'myCity' } | Select-Object -ExpandProperty Subnets


that’s better!