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.
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:
The script version just showed is obviously quite complicated - it is here just for demonstration purposes. A shorter approach uses the ADSystemInfo COM object:
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.
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: