JSI Tip 9937. How can I determine the distinguished name of the domain I am logged onto, using standard commands?

Jerold Schulman

November 30, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today

In tip 7680, we determined the distinguished name of the forest root domain.

in tip 8540, we scripted DomainDN.bat to retrieve the distinguished name of the domain you are logged on to using the DSQUERY Active Directory command-line tool.

I have scripted DomainDN.bat to retrieve the distinguished name of the domain you are logged on to using standard commands.

The syntax for using DomainDN.bat is:

DomainDN DN

Where DN is a call directed environment variable that will contain the distinguished name of the domain you are logged on to.

Example:

When I use DomainDN DN, DN is set to DC=JSIINC,DC=COM.

DomainDN.bat contains:

@echo offif {%1}=={} @echo Syntax Call DomainDN DomainName&exit /b 1if exist "%TEMP%DomainDN.vbs" goto doit@echo Set objRootDSE = GetObject("LDAP://rootDSE")>"%TEMP%DomainDN.vbs"@echo strDomain = objRootDSE.Get("defaultNamingContext")>>"%TEMP%DomainDN.vbs"@echo Wscript.Echo strDomain>>"%TEMP%DomainDN.vbs":doitfor /f "Tokens=* Delims=:" %%c in ('cscript //Nologo "%TEMP%DomainDN.vbs"') do set %1=%%cexit /b 0



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