JSI Tip 7680. How do I determine the forest root domain in a batch?
Jerold Schulman
January 21, 2004
1 Min Read
I have scipted ForestRootDomain.bat to determine the forest root domain in a batch.
The syntax for using ForestRootDomain.bat is:
call ForestRootDomain VAR [/DN]
where VAR is a call directed environment variable that will contain the forest root domain, and /DN is an optional switch which returns the distinguished name of the forest root domain in VAR.
Example:
When is use call ForestRootDomain VAR, the %VAR% variable is returned as JSIINC.COM.
When is use call ForestRootDomain VAR /DN, the %VAR% variable is returned as DC=JSIINC,DC=COM.
ForestRootDomain.bat contains:
@echo offif {%1}
{} @echo Syntax Call ForestRootDomain VAR [/DN]&exit /b 1setlocal@echo Set objSysInfo = CreateObject("ADSystemInfo")>"%TEMP%ForestRootDomain.vbs"@echo Wscript.Echo "Forest DNS Name: " ^& objSysInfo.ForestDNSName>>"%TEMP%ForestRootDomain.vbs"if /i not {%2}
{/dn} goto run@echo Set objRootDSE = GetObject("LDAP://RootDSE")>"%TEMP%ForestRootDomain.vbs"@echo Wscript.Echo "Root Domain: " ^& objRootDSE.Get("RootDomainNamingContext")>>"%TEMP%ForestRootDomain.vbs":runfor /f "Tokens=1* Delims=:" %%c in ('cscript //Nologo "%TEMP%ForestRootDomain.vbs"') do set frd=%%dset frd=%frd:~1%del /q "%TEMP%ForestRootDomain.vbs"endlocal&set %1=%frd%exit /b 0
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like