header image

Domain Controllers and their sites

Posted by: | May 14, 2014 | 2 Comments |

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.

under: PowerShell and Active Directory


  1. By: Emmanuel on May 15, 2014 at 1:09 am      

    Why don’t use the “msds-sitename” computer attribute of the DC ?

  2. By: RichardSiddaway on May 15, 2014 at 5:55 am      

    That would work as well.

    As its says in the post this is one way to solve the problem