Friday, July 29, 2016

What Subnets Are In My Site

Hi folks,

You have probably read about retrieving domain controller in the site where computer or server is located. You can read this post here. In that post I tried to

I have capitalized on this blog post from Microsoft which addresses generic situation when you try to retrieve information about AD subnets in ad generic AD site (with the default name).

In my scenario I was trying to understand which subnets are configured in the AD site where my computer (server) is located.

The script queries WMI for the value of the AD site name where computer is located and feeds it to the $SiteName variable. Then it queries domain controllers by using $SiteName as a variable in order to retrieve domain controllers located in the same AD site:


$siteName =  [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name

$configNCDN = (Get-ADRootDSE).ConfigurationNamingContext

$siteContainerDN = (“CN=Sites,” + $configNCDN)

$siteDN = “CN=” + $siteName + “,” + $siteContainerDN

$siteObj = Get-ADObject -Identity $siteDN -properties “siteObjectBL”, “description”, “location”

foreach ($subnetDN in $siteObj.siteObjectBL) {

    Get-ADObject -Identity $subnetDN -properties “siteObject”, “description”, “location” |select Name,SiteObject

}

I hope you find it helpful.

Enjoy

No comments:

Post a Comment