Export AD Sites and Subnets

Hi Guys! Welcome back to another Blog. I have built a script that will get AD Sites and Subnets from a Client machine (Doesn’t have to be a server), The reason why I wrote this is to show how powerful PowerShell is.

My objective is to show that PowerShell can do a lot of things not from a server end but from Client as well.

You can leverage the Static Class and methods to achieve a lot of the functions. For an example if you want to know how to see what classes are available click this Link.

Let me know show in Powershell now, to use a Dot Net Class in PowerShell you can use as the following

[System.className]
Identifying System Class

There are also Namespaces which can also be accessed via PowerShell. as below

Identifying System Namespaces

By accessing the namespaces within a namespaces to find the correct Class you can do amazing things such as this script below.

$MachineName = hostname
$GetSites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
$Report = @()

Foreach($Site in $GetSites){
   $Report += new-object -type PSObject -Property (@{
       SiteName = $Site.Name
       SubNets = $Site.Subnets -Join ","
       Servers = $Sites.Servers -Join ","
   })
}

$Report | out-gridview

Got the details and passed it to a Hash and displayed out as a table for easier view.

Result with blur

Unfortunately I cannot show you the result.

Hopefully this will help you.

Published by iamfazul

Author of the site

One thought on “Export AD Sites and Subnets

  1. Hey there! This post couldn’t be written any better!
    Reading through this post reminds me of my old room mate!
    He always kept chatting about this. I will forward this page to him.
    Pretty sure he will have a good read. Thanks for sharing!

    Like

Leave a comment