Recipe 11.20 Finding the Site for a Client

11.20.1 Problem

You want to find which site a client computer is in.

11.20.2 Solution

11.20.2.1 Using a command-line interface

In the following command, replace <HostName> with the name of the host you want to find the site for:

> nltest /server:<HostName> /DsGetSite
11.20.2.2 Using VBScript

Although you cannot use it directly from a scripting language like VBScript, Microsoft provides a DsGetSiteName method that can be used by languages, such as Visual Basic and C++, to retrieve site coverage information. In fact, the nltest command shown in the CLI solution is a wrapper around this method.

The IADsTool interface provides a wrapper around this method:

set objIadsTools = CreateObject("IADsTools.DCFunctions") strSite = objIadsTools.DsGetSiteName("<HostName>") Wscript.Echo "Site: " & strSite

11.20.3 Discussion

Each domain controller has a server object that is contained with a site. Clients are different they are associated with a site based on their IP address and the corresponding subnet that it matches is in the Subnets container. The client site information is important because it determines the domain controller the client authenticates with. If the client's IP address does not match a subnet range of any of the subnets stored in Active Directory, it will randomly pick a site to use, which means it could authenticate against any domain controller in the domain. See Recipe 11.21 for a way to hardcode the site association for a client.

11.20.4 See Also

Recipe 11.21 for forcing a host to a particular site, MS KB 247811 (How Domain Controllers Are Located in Windows), and MSDN: DsGetSiteName



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

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