10.7. Finding a Computer's Active Directory Site
You want to find the Active Directory site a computer is part of, which is based on the IP address of the computer.
Using a command-line interface
In the following command, replace
with the name of the host whose site you want to find.
> nltest /server:
To force a computer to use a particular site, modify the registry as follows:
> reg add HKLM\System\CurrentControlSet\Services\Netlogon\Parameters /v SiteName /t REG_SZ /d
Although you cannot use it directly from a scripting language
such as 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
command shown in the CLI solution is a wrapper around this
The IADsTools interface provides a wrapper around this method.
set objIadsTools = CreateObject("IADsTools.DCFunctions") strSite = objIadsTools.DsGetSiteName("
<HostName>") Wscript.Echo "Site: " & strSite ' This code forces the host the script is run on to use a particular site ' ------ SCRIPT CONFIGURATION ------ strSite = "
<SiteName>" ' e.g., Raleigh ' ------ END CONFIGURATION --------- strNetlogonReg = "SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" const HKLM = &H80000002 set objReg = GetObject("winmgmts:root\default:StdRegProv") objReg.SetStringValue HKLM, strNetlogonReg, "SiteName", strSite WScript.Echo "Set SiteName to " & strSite