VBScript programs that use ADO to enumerate all Domain Controllers in the
The first program finds all objects of class nTDSDSA in the Configuration container of Active Directory. This container is replicated to all Domain Controllers in the domain. The parent object of any object with objectClass equal to nTDSDSA is a Domain Controller object, which in turn is in a Servers container. The parent of the Servers container is the Site container, corresponding to the site the DC is assigned to. For each Domain Controller found, this program outputs the NetBIOS name of the DC, the DNS host name, the Distinguished Name of the DC, and the name of the site it is assigned to.
EnumDCs.txt <<-- Click here to view or download the program
The second program also uses ADO, but this time filters on objects of class "computer" where the ADS_UF_SERVER_TRUST_ACCOUNT bit of the userAccountControl attribute is set. The bit mask for this setting is equal to &H2000 (decimal 8192). This bit is only set if the object is a Domain Controller. This program also outputs the NetBIOS name, the Distinguished Name, and the DNS host name of each Domain Controller, but not the name of the site the DC is assigned to. This program should be more efficient than the first because it does not require binding to any objects in Active Directory.
EnumDCs2.txt <<-- Click here to view or download the program