tags:

views:

1099

answers:

1

Can ADO access attributes other that ADsPath and Name when bound to an LDAP server?

Below is the code I use to bind to and query a LDAP server on the internet:

Set ado = CreateObject("ADODB.Connection")                     
ado.Provider = "ADSDSOObject"
ado.Properties("User ID") = ""                                
ado.Properties("Password") = ""
ado.Properties("Encrypt Password") = False
ado.Open "NameSearch"                                     


serverName = "xxxxxx.xxxx.xxx"                           
filterStr = "(objectClass=*)"     

Set Ol= ado.Execute("<LDAP://" & serverName & ">;" & filterStr & ";ADsPath;SubTree")

While Not Ol
    WScript.Echo Ol.Fields(0).value
    Ol.MoveNext                                        
Wend

Also how do assign the search base in the above code to "o= xxxxxx University;c=US"?

+2  A: 

See How To Use ADO to Access Objects Through an ADSI LDAP Provider.

The connection object Execute method's CommandText (first object) is an LDAP query composed of four elements separated by semicolons, in the following format:

<LDAP://server/adsidn>;ldapfilter;attributescsv;scope

where adsidn is the distinguished name (DN) of the starting point for your query expressed ADsPath format with "/" separators and the root of the namespace to the left. You can also use an X.500 style attributed name format with the relative distinguished names separated by commas and the root of the name space to the right.

To return the ADsPath, class, and cn attributes of all the objects in all the recipient containers in an Exchange server, you can use the following CommandText (in URL format):

LDAP:; (objectClass=*);ADsPath,objectClass,cn;subtree

To put it all together,

  Dim conn As ADODB.Connection
  Dim rs As ADODB.Recordset

  Set conn = New ADODB.Connection
  conn.Provider = "ADSDSOObject"
  conn.Open "ADs Provider"

  Set rs = conn.Execute( _ 
        "<LDAP://server/o=organization/o=xxxxxx University/c=US>;" _
        & "(objectClass=*);ADsPath,objectClass,cn;subtree")

  While Not rs.EOF
     Debug.Print rs.Fields(0).Value, rs.Fields(1).Value, _
           rs.Fields(2).Value
     rs.MoveNext
  Wend

  conn.Close
eed3si9n