locked
ASP.NET Active Directory Question RRS feed

  • Question

  • User-1483722223 posted

    I've got a connection to my ActiveDirectory like this:

    Dim myDE As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath, "********", "%*******%")

    and this is working ... no errors

    I want to iterate through the users in AD to get the email addresses of everyone.

    Any Ideas?

    thanks for your time if you can spare it.

    Tuesday, May 6, 2008 3:02 PM

Answers

  • User-275891335 posted

    This may get you going in the right direction 

     

    Dim objGroupEntry As DirectoryEntry

    Dim objSearchADAM As DirectorySearcher

    Dim objSearchResults As SearchResultCollection Dim objResult As SearchResult

    objSearchADAM = New DirectorySearcher(New DirectoryEntry(LDAP://{your ldap}))

    objSearchADAM.PropertiesToLoad.Add("mail")

    objSearchADAM.SearchScope = SearchScope.Subtree

    objSearchADAM.Filter = "(&(objectClass=user)(objectCategory=person))"

    objSearchResults = objSearchADAM.FindAll()

    For Each objResult In objSearchResults

    objGroupEntry = objResult.GetDirectoryEntry()

    Console.WriteLine("email: " & objGroupEntry.Properties("mail").Value)

    Next objResult

    Console.Read()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2008 4:14 PM
  • User-275891335 posted

    You may have to make a tweak or two but I'm glad we were able to get you headed in the right direction.

    Besure to mark the forum as "answered"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2008 4:48 PM

All replies

  • User-275891335 posted

    This may get you going in the right direction 

     

    Dim objGroupEntry As DirectoryEntry

    Dim objSearchADAM As DirectorySearcher

    Dim objSearchResults As SearchResultCollection Dim objResult As SearchResult

    objSearchADAM = New DirectorySearcher(New DirectoryEntry(LDAP://{your ldap}))

    objSearchADAM.PropertiesToLoad.Add("mail")

    objSearchADAM.SearchScope = SearchScope.Subtree

    objSearchADAM.Filter = "(&(objectClass=user)(objectCategory=person))"

    objSearchResults = objSearchADAM.FindAll()

    For Each objResult In objSearchResults

    objGroupEntry = objResult.GetDirectoryEntry()

    Console.WriteLine("email: " & objGroupEntry.Properties("mail").Value)

    Next objResult

    Console.Read()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2008 4:14 PM
  • User-1483722223 posted
    Thanks for your help.  That got me going.  I plugged in my LDAP info and away it went.  Awesome.  I was missing the person category on mine and it was of course failing.  Thanks again.
    Tuesday, May 6, 2008 4:38 PM
  • User-275891335 posted

    You may have to make a tweak or two but I'm glad we were able to get you headed in the right direction.

    Besure to mark the forum as "answered"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2008 4:48 PM