PowerShell for Windows Admins

May 14 2014   1:09PM GMT

Domain Controllers and their sites

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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:

CN=SERVER02

CN=Site1

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.

 

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: