'# From the book "Managing Enterprise Active Directory Services"
'# ISBN: 0-672-32125-4
ON ERROR RESUME NEXT
Dim aDsPath, user, passwd, server
domain = "xyz.com" 'domain to retrieve DCs from
user = "administrator@xyz.com"
passwd = "password"
' Need to get domain's default naming context
' (i.e. the domains DN)
Dim rootDSE
Set rootDSE = GetObject("LDAP://" & domain & "/RootDSE")
aDsPath = "LDAP://" & domain & "/" & _
rootDSE.Get("defaultNamingContext")
' Open the domain object with the supplied credentials
Dim ldapObj
Set ldapObj = GetObject("LDAP:")
Dim domainObj
Set domainObj = ldapObj.OpenDsObject(aDsPath,user,passwd,1)
' Retrieve the NTDS DNs that master for this domain
Dim masteredBy
masteredBy = domainObj.GetEx("masteredBy")
' Iterate through each NTDS object, get its parent
' and print out the dNSHostName attribute
Dim ntdsDN
for each ntdsDN in masteredBy
Dim ntdsObj
ntdsDN = "LDAP://" & strDomain & "/" & ntdsDN
Set ntdsObj = ldapObj.OpenDsObject(ntdsDN,user,passwd,1)
Dim serverObj
Set serverObj = ldapObj.OpenDsObject(ntdsObj.Parent,user,passwd,1)
Wscript.echo serverObj.Get("dNSHostName")
next
|