Trying to get members of a group, but my code wont work RRS feed

  • Question

  • User-529154869 posted

    Dim de As New DirectoryEntry( "LDAP://OU=myOU,OU=myOU,DC=myDC,DC=myDC")

    Dim ds As DirectorySearcher = New DirectorySearcher(de)

    Dim strFilter As String

    strFilter = "(&(objectClass=user)(objectCategory=person)(memberOf=CN=myGroup))"

    ds.Filter = strFilter

    ds.SearchScope = SearchScope.Subtree


    Dim Result As SearchResult

    For Each Result In ds.FindAll()

    Dim key As String

    For Each key In Result.Properties.PropertyNames

    Dim o As Object

    For Each o In Result.Properties(key)

    Trace.Warn("key: " & key & "o: " & o)

    Next o

    Next key



    This code does not return anything when i know for sure there are members under "mygroup".  I know i must be missing something.  Please point me in the right direction.  Thanks!!

    Friday, March 3, 2006 9:25 PM

All replies

  • User1354132231 posted
    To get the members of a group, we need to expand it.  I will explain the simple version (non-recusive).  You want to bind to the group you are interested in expanding the membership for ('de' in your case should be this).  Next, simply use a foreach loop and iterate over the 'member' attribute on the DirectoryEntry.

    There are more sophisticated methods using recursion and what not (covered in my book), but this should get you started at least.
    Wednesday, March 8, 2006 5:07 PM