[ Team LiB ] |
Recipe 3.20 Finding the Domain Controllers or Global Catalog Servers in a Site3.20.1 ProblemYou want a list of the domain controllers or global catalog servers in a specific site. 3.20.2 Solution3.20.2.1 Using a graphical user interface
3.20.2.2 Using a command-line interfaceThe 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 DiscussionEach 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. |
[ Team LiB ] |