Submitted By: Umesh Chandra Thakur

Displays Active Directory naming contexts.

Visual Basic
Edit|Remove
Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
'objCommand.Properties("search filter") = "(msDS-SDReferenceDomain=*)"

Set objRootDSE = GetObject("LDAP://rootDSE")
strConfiguration = objRootDSE.Get("configurationNamingContext")
strPartitions = "<LDAP://CN=Partitions," & strConfiguration & ">"

objCommand.CommandText = strPartitions & ";(&(objectClass=crossRef));ncName,dnsRoot;subtree"  
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

wscript.echo "Naming-Contexts [DNS Root]"
wscript.echo "--------------------------"
Do Until objRecordSet.EOF
    strncName = objRecordSet.Fields("ncName").Value
    strdnsRoot = objRecordSet.Fields("dnsRoot").Value
        wscript.echo strncName & " [" & join(strdnsRoot) & "]" 
    objRecordSet.MoveNext
Loop