views:

9

answers:

0

I have the following code that gets the members of a distribution list but if there's a another list within it I'd like to get the members from it too.

Try Dim path As String = String.Empty path = "LDAP://...."

        Dim de As DirectoryEntry = New DirectoryEntry(path)
        Dim ds As DirectorySearcher = New DirectorySearcher(de)

        ds.PropertiesToLoad.Clear()
        ds.PropertiesToLoad.Add("member")
        ds.Filter = "CN=DL NAME"

        Dim results As SearchResultCollection
        results = ds.FindAll

        Dim result As SearchResult

        Dim members As String = ""

        For Each result In results
            For Each member As String In result.GetDirectoryEntry.Properties("member")

                Dim selIndex As Integer = member.IndexOf("CN=") + 3
                Dim selEnd As Integer = member.IndexOf("OU") - 3
                members &= member.Substring(selIndex, selEnd).Replace("\\", "").Replace("\", "").Replace(",", "") & vbCrLf

            Next
        Next

        Console.WriteLine(members)
        results.Dispose()

    Catch ex As Exception
        Console.WriteLine(ex.Message.ToString)
    End Try