Printout Header
RSS Feed

How to detect the Name of the own Active Directory Domain


When you script in Active Directory environments, you will often need the name of the own domain, meaning the domain where the user who runs th script is member of. This could be an LDAP path name, an (oldschool) NetBIOS name or the full qualified DNS domain name.


The LDAP path (=distinguished name) of the own domain


This script finds the LDAP path name (=the distinguishd name) of the own domain.

Set rootDSE = GetObject("LDAP://rootDSE") domainDN = rootDSE.Get("defaultNamingContext") WScript.Echo domainDN

The NetBIOS name of the own domain


This script finds the NetBIOS short name of the own domain. We use nothing but LDAP requests here:

Set rootDSE = GetObject("LDAP://rootDSE") domainDN = rootDSE.Get("defaultNamingContext") configDN = rootDSE.Get("configurationNamingContext") Set partitions = GetObject("LDAP://cn=partitions," & configDN) For Each nameSpace In partitions If (nameSpace.nCName = domainDN) Then Exit For Next domainNETBios = nameSpace.nETBIOSName WScript.Echo domainNETBios

The script version just showed is obviously quite complicated - it is here just for demonstration purposes. A shorter approach uses the ADSystemInfo COM object:

Set aio = CreateObject("ADSystemInfo") domainNETBios = aio.DomainShortName WScript.Echo domainNETBios

You can also use the WinNTSystemInfo COM object for this. Whether you choose the WinNTSystemInfo or ADSystemInfo depends on the other information you might want to read from these COM objects.

Set wio = CreateObject("WinNTSystemInfo") domainNameNeBIOS = wio.DomainName WScript.Echo domainNETBios

The DNS name of the own domain


This script finds the full qualified DNS name of the own domain. We use the ADSystemInfo COM object here again:

Set aio = CreateObject("ADSystemInfo") domainDNS = aio.DomainDNSName WScript.Echo domainDNS