Ever tried to run a VBS scripts that queries Active Directory in another domain or from a workstation that is not a domain member? Than you have probably seen this error before:

Error MessageError MessageError Message

This is because the default settings for Chasing referrals is set to ADS_CHASE_REFERRALS_NEVER.

Add the line below to your script to make it work.

Const ADS_CHASE_REFERRALS_ALWAYS = &H60
objCommand.Properties("Chase referrals") = ADS_CHASE_REFERRALS_ALWAYS

So in a script it would look like this:

Const ADS_SCOPE_SUBTREE = 2
Const ADS_CHASE_REFERRALS_ALWAYS = &H60  

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.Properties("Chase referrals") = ADS_CHASE_REFERRALS_ALWAYS  

objCommand.CommandText = _
    "Select distinguishedName from " & _
        "’LDAP://cn=Configuration,DC=MyDomain,DC=Local’ " _
            & "where objectClass=’nTDSDSA’"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE  

Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst  

Do Until objRecordSet.EOF
    Wscript.Echo "Computer Name: " & _
        objRecordSet.Fields("distinguishedName").Value
    objRecordSet.MoveNext
Loop

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
convert this post to pdf.