Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Querying Active Directory

    Good afternoon folks

    I am querying the activedirectory with VBA to populate a combobox successfully with a list of names.
    I get the names fine with rs.fields("name")
    I can return telephone numbers with rs.fields("telephonenumber")

    What is the field name that returns the email address. I had assumed rs.fields("emailaddress")

    The query
    strSql = "Select name,telephoneNumber, "
    strSql = strSql & "From 'LDAP://DC=ara,DC=local' "
    strSql = strSql & "WHERE objectCategory='Person' "
    strSql = strSql & "AND objectClass = 'User' "
    strSql = strSql & "AND Company = 'xyz co'"

    works fine

    but
    strSql = "Select name,telephoneNumber, emailaddress "
    strSql = strSql & "From 'LDAP://DC=ara,DC=local' "
    strSql = strSql & "WHERE objectCategory='Person' "
    strSql = strSql & "AND objectClass = 'User' "
    strSql = strSql & "AND Company = 'xyz co'"

    stops dead.

    that leads me to believe that emailaddress is the wrong field name.

    Can I be pointed to a valid list of field names within AD

    Thanks in advance

    Geof

  2. #2
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Querying Active Directory

    Hi Folks
    Got it.

    The field is "mail"
    How hard is that?

    The error was a a total red herring created by the keyboard-chair interface.

    Geof

  3. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Querying Active Directory

    Good evening loungers
    It seems that little is easy on this topic. I am sure that is why some make the big bucks.

    I found this forum post to be interesting

    http://forums.aspfree.com/archive/t-21470/...ails-using-ADSI

    city field = "l'

    I ask you. ??

    Cheers
    Geof

  4. #4
    Lounger
    Join Date
    Sep 2004
    Location
    Evesham, Worcestershire, England
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Querying Active Directory

    Robbie Allen's book "Active Directory Cookbook" is great for this sort of thing. The scripts are available on :

    http://rallenhome.com/books/adcookbook/code.html

    Have a look at script 4.2 Viewing the attributes of a object. It is easy to build that into an ASP page if you want to look up user's AD attributes regularly (though you should secure that page!)

  5. #5
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Querying Active Directory

    Thanks for that Reggie.
    It is really useful stuff.
    Geof

  6. #6
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Querying Active Directory

    Hi folks
    For any that are interested here is the relevant section that solved my problem.
    '----------------------
    Set oConnection1 = CreateObject("ADODB.Connection")
    Set oCommand1 = CreateObject("ADODB.Command")
    ' Open the connection.
    oConnection1.Provider = "ADsDSOObject" ' This is the ADSI OLE-DB provider name
    oConnection1.Open "Active Directory Provider"
    ' Create a command object for this connection.
    Set oCommand1.ActiveConnection = oConnection1

    '-------------------------------------------------
    ' Compose a search string.
    ''-------------------------------------------------
    strSql = "Select sn, givenName, name , initials,telephoneNumber,mail,title,streetAddress, l,co, department, description "
    strSql = strSql & "From 'LDAP://DC=xyz,DC=abc " ' leave the space between the single & double quote
    strSql = strSql & "WHERE objectCategory='Person' "
    strSql = strSql & "AND objectClass = 'User' "
    strSql = strSql & "AND Company = xyz"
    oCommand1.commandText = strSql
    ' Execute the query.
    Set rs = oCommand1.Execute
    ReDim aryStaff(rs.RecordCount, 11)

    rs.moveFirst

    While Not rs.EOF
    aryStaff(i, 0) = rs.Fields("Name")
    aryStaff(i, 1) = rs.Fields("sn")
    aryStaff(i, 2) = rs.Fields("givenName")
    aryStaff(i, 3) = rs.Fields("initials")
    aryStaff(i, 4) = rs.Fields("telephoneNumber")
    aryStaff(i, 5) = rs.Fields("mail")
    aryStaff(i, 6) = rs.Fields("title")
    aryStaff(i, 7) = rs.Fields("streetaddress")
    aryStaff(i, 8) = rs.Fields("l")
    aryStaff(i, 9) = rs.Fields("co")
    aryStaff(i, 10) = rs.Fields("department")
    aryStaff(i, 11) = rs.Fields("description")

    i = i + 1
    rs.movenext
    Wend

    Cheers
    Geof

  7. #7
    Lounger
    Join Date
    Sep 2004
    Location
    Evesham, Worcestershire, England
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Querying Active Directory

    And don't forget the section:
    ' ---------------------------------------------------------------
    ' From the book "Active Directory Cookbook" by Robbie Allen
    ' Publisher: O'Reilly and Associates
    ' ISBN: 0-596-00466-4
    ' Book web site: http://rallenhome.com/books/adcookbook/code.html
    ' ---------------------------------------------------------------
    Let's give credit where credit due.

    Glad the link was of use.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •