JSI Tip 8540. How can I retrieve the distinguished name of the domain I am logged on to?
Jerold Schulman
October 4, 2004
1 Min Read
You can attempt to determine the distinguished name of the domain your are logged on to by parsing the %USERDNSDOMAIN% environment variable.
In How do I determine the forest root domain in a batch, I used vbscript to retrieve the forest root domain.
To retrieve the domain's DN from Active Directory, I have scripted DomainDN.bat.
DomainDN.bat uses the DSQUERY Active Directory command-line tool.
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: DomainDN DN&goto :EOFfor /f "Skip=1 Tokens=*" %%d in ('dsquery * domainroot -filter "(&(objectCategory=domainDNS)(objectClass=domain))" -attr distinguishedName -limit 0') do ( set %1=%%d)
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