Skip to Content
Active Directory Cookbook
book

Active Directory Cookbook

by Robbie Allen
September 2003
Intermediate to advanced
624 pages
15h 49m
English
O'Reilly Media, Inc.
Content preview from Active Directory Cookbook

3.8. Finding the Domain Controllers for a Domain

Problem

You want to find the domain controllers in a domain.

Solution

Using a graphical user interface

  1. Open the Active Directory Users and Computers snap-in.

  2. Connect to the target domain.

  3. Click on the Domain Controllers OU.

  4. The list of domain controllers for the domain will be present in the right pane.

Using a command-line interface

> netdom query dc /Domain:<DomainDNSName>

Using VBScript

' This code displays the domain controllers for the specified domain.
' ------ SCRIPT CONFIGURATION ------
strDomain = "<DomainDNSName>"  ' e.g. emea.rallencorp.com
' ------ END CONFIGURATION ---------

set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
set objDomain = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext"))
strMasteredBy = objDomain.GetEx("masteredBy")
for each strNTDSDN in strMasteredBy
   set objNTDS = GetObject("LDAP://" & strNTDSDN)
   set objServer = GetObject(objNTDS.Parent)
   Wscript.echo objServer.Get("dNSHostName")
next

Discussion

There are several ways to get a list of domain controllers for a domain. The GUI solution simply looks at the computer objects in the Domain Controllers OU. Whenever you promote a domain controller into a domain, a computer object for the server gets placed into the Domain Controllers OU off the root of the domain. Some administrators may move their domain controller computer objects to different OUs, so this test does not guarantee accuracy in all cases.

The CLI and VBScript solutions take a slightly ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Active Directory Administration Cookbook

Active Directory Administration Cookbook

Sander Berkouwer
Active Directory Cookbook, 3rd Edition

Active Directory Cookbook, 3rd Edition

Laura E. Hunter, Robbie Allen
Active Directory Cookbook, 4th Edition

Active Directory Cookbook, 4th Edition

Brian Svidergol, Robbie Allen

Publisher Resources

ISBN: 0596004648Supplemental ContentCatalog PageErrata