In tip 3093, we used Nltest.exe to determine What SITE is a Domain Controller was located in.

Using only native commands, I have scripted DCSite.bat to determine the SITE of a specified domain controller.

The syntax for using DCSite.bat is:

\[Call\] DCSite NetBIOSDCName SiteName

Where:

<b>NetBIOSDCName</b> is the <b>NetBIOS</b> computer name of a domain controller.

<b>SiteName</b>      is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a> that will contain the SITE that <b>NetBIOSDCName</b> belongs to.
DCSite.bat contains:
@echo off
if \{%2\}==\{\} @echo Syntax: DCSite NetBIOSDCName SiteName&goto :EOF
if exist "%TEMP%\DCSite.vbs" goto doit
@echo dcName = Wscript.Arguments(0)>"%TEMP%\DCSite.vbs"
@echo set obj = CreateObject("ADSystemInfo")>>"%TEMP%\DCSite.vbs"
@echo Wscript.Echo obj.GetDCSiteName(dcName)>>"%TEMP%\DCSite.vbs"
:doit
for /f "Tokens=*" %%s in ('cscript //nologo "%TEMP%\DCSite.vbs" %1') do (
 set %2=%%s
)