Skip navigation

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

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 off
if \{%1\}==\{\} @echo Syntax Call DomainDN DomainName&exit /b 1
if 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"
:doit
for /f "Tokens=* Delims=:" %%c in ('cscript //Nologo "%TEMP%\DomainDN.vbs"') do set %1=%%c
exit /b 0



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish