• Querying Active Directory

    Author
    Topic
    #424077

    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

    Viewing 0 reply threads
    Author
    Replies
    • #972898

      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

      • #972913

        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

        • #979660

          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!)

        • #979835

          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

          • #980022

            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.

    Viewing 0 reply threads
    Reply To: Querying Active Directory

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: