Recipe 3.20 Finding the Domain Controllers or Global Catalog Servers in a Site

3.20.1 Problem

You want a list of the domain controllers or global catalog servers in a specific site.

3.20.2 Solution

3.20.2.1 Using a graphical user interface
  1. Open the Active Directory Sites and Services snap-in.

  2. In the right pane, expand the site that contains the domain controller.

  3. For the list of domain controllers, expand the Servers container.

  4. To find the global catalog servers, expand each domain controller, right-click on NTDS Settings, and select Properties.

  5. Global catalog servers will have the box checked beside Global Catalog.

3.20.2.2 Using a command-line interface

The following query finds all domain controllers in specified site.

> dsquery server -site <SiteName>

To find only the global catalog servers in a site, use the same command with the -isgc option.

> dsquery server -site <SiteName> -isgc
3.20.2.3 Using VBScript
' This code prints the domain controllers in a site and then ' prints the global catalog servers in the site ' ------ SCRIPT CONFIGURATION ------ strSite   = "<SiteName>"       ' e.g. Default-First-Site-Name strForest = "<ForestDNSName>"  ' e.g. rallencorp.com                  ' ------ END CONFIGURATION --------- set objRootDSE = GetObject("LDAP://" & strForest & "/RootDSE") strADsPath = "<LDAP://cn=servers,cn=" & strSite & ",cn=sites," & _               objRootDSE.Get("configurationNamingContext") & ">;" strFilter  = "(objectcategory=ntdsdsa);" strAttrs   = "distinguishedName;" strScope   = "SubTree" WScript.Echo "Domain controllers in " & strSite & ":" set objConn = CreateObject("ADODB.Connection") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" set objRS = objConn.Execute(strADsPath & strFilter & strAttrs & strScope) objRS.MoveFirst while not objRS.EOF     Set objNTDS = GetObject("LDAP://" & objRS.Fields(0).Value)     Set objServer = GetObject( objNTDS.Parent )     Wscript.Echo " " & objServer.Get("dNSHostName")     objRS.MoveNext wend ' Global Catalog filter strFilter  = "(&(objectcategory=ntdsdsa)(options=1));" WScript.Echo "" WScript.Echo "Global Catalogs in " & strSite & ":" set objRS = objConn.Execute(strADsPath & strFilter & strAttrs & strScope) objRS.MoveFirst while not objRS.EOF     set objNTDS = GetObject("LDAP://" & objRS.Fields(0).Value)     set objServer = GetObject( objNTDS.Parent )     Wscript.Echo " " & objServer.Get("dNSHostName")     objRS.MoveNext wend

3.20.3 Discussion

Each domain controller has a server object within the Servers container for the site it is a member of (e.g., cn=DC1,cn=Servers,cn=MySite, cn=site, cn=configuration, dc=rallencorp, dc=com). Since other types of servers can have server objects in a site's Servers container, domain controllers are differentiated by the nTDSDSA object that is a child of the server object (e.g., cn=NTDSSettings,cn=DC1,cn=Servers,cn=MySite, cn=site, cn=confiugration, dc=rallencorp, dc=com). Querying for this nTDSDSA objects will return a list of domain controllers in the site. Locating global catalog servers consists of the same query, except where the low-order bit of the options attribute of the nTDSDSA object is equal to 1.



Active Directory Cookbook
Active Directory Cookbook, 3rd Edition
ISBN: 0596521103
EAN: 2147483647
Year: 2006
Pages: 456

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net