retrieve Email addresses from all the members of a group

May 30 2010 3:11 PM
I want to have all the mail addresses from the members of a group.
So i have all the members of the group but when I retrieve the "mail" addresses the application is slow.
Maybe its better to use ADO but how can I do that?
here is the code I used:
The comment selection makes it slow.

Public Sub GetMailAdressess(ByVal GroupName As String)

Dim dsDirectorySearcher As New DirectorySearcher
Dim strUsers As String
Dim strUserEmail As String = String.Empty
Counter = 0

With dsDirectorySearcher
.Filter = "SAMAccountName=" & GroupName
.PropertiesToLoad.Add("member")

Try
Dim dsResult As SearchResult = .FindOne
Dim intCounter As Integer
Dim Position As Integer
If dsResult Is Nothing Then
MsgBox("Er zijn geen zoek resultaten!", 48)
Exit Sub
End If

Dim dirGroup As New DirectoryEntry(dsResult.Path)
Dim propCollection As PropertyCollection = dirGroup.Properties
Dim strRemove As String = ""

Cursor.Current = Cursors.WaitCursor

For intCounter = 0 To dsResult.Properties("member").Count - 1
strUsers = dsResult.Properties("member")(intCounter).ToString

Position = strUsers.IndexOf(",")
strRemove = strUsers.Substring(0, Position)
strRemove = strRemove.Remove(0, 3)

'Dim dSearch As DirectorySearcher = New DirectorySearcher("(anr=" & strRemove & ")")
'Dim sResult As SearchResult
'Dim userEmail As String

'sResult = dSearch.FindOne
'Dim fullName As String = sResult.Properties("name")(0)
'userEmail = sResult.Properties("mail")(0)

ExportAD.lstQuery.Items.Add(strRemove)
Application.DoEvents()
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With

End Sub