Domain Controllers and their sites

Its relatively straightforward to find the domain controllers in your AD domain and its equally as straightforward to find the sites in your AD forest. Discovering which domain controllers are in which site is a bit more problematic.

One way is look at the nTDSDSA objects. These are in the configuration naming context and their distinguished names take the form:

CN=NTDS Settings,CN=SERVER02,CN=Servers,CN=Site1,CN=Sites,CN=Configuration,DC=Manticore,DC=org

Similar to the information you see in AD Sites and Services.

This script produces a table of domain controllers and sites.

Get-ADObject -SearchBase (Get-ADRootDSE | select -ExpandProperty configurationNamingContext) -LDAPFilter “(ObjectClass=nTDSDSA)” |
select -ExpandProperty DistinguishedName |
foreach {
$data = $psitem -split “,”
$props = [ordered]@{
   DC = ($data[1] -split “=”)[1]
   Site = ($data[3] -split “=”)[1]

New-Object -TypeName PSObject -Property $props


Start by getting the rootdse, using Get-ADRootDSE, of the domain and finding the the distinguished name of the configuration naming context. Use that as the value for the –SearchBase parameter of Get-ADObject. An LDAP filter restricts the return to objects of type nTDSDSA.

Select the distinguished name and pipe into a foreach-object block. 

Split the distinguishednames on the comma separator and then use elements 1 and 3 of the resultant array which are, respectively:



Split each on the = sign and take the second element. This gives you the DC name and the corresponding site name.  Use this to create an object for output.

This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s