I have scripted GetDC.bat to return a call directed environment variable with the name of a domain controller in the specified domain, or NO, if a domain controller cannot be located.

The syntax for using GetDC.bat is:

call getdc DomainName DomainController

where DomainName is the name of the domain you are interrogating
and DomainController is the call directed environment variable that will contain \\DomainControllerComputerName, if you used a NetBIOS domain name,
or \\DomainControllerComputerName.DNSDomainName (like \\JSI001.JSIINC.COM) if you used a DNS domain name.

GetDC.bat contains:

@echo off                              if \{%2\}

\{\} @echo Syntax: Call GetDC DomainName DomainController&goto :EOF set %2=NO for /f "Tokens=1*" %%a in ('nltest /dsgetdc:%1') do if /i "%%a"

"DC:" set %2=%%b