I am trying to get membership in a user group and limit the results to those that match the string, i.e. I'm only interested in membership in a user group, where the group starts with "test -".
The following is information about what I played with, even if the user is different from several groups corresponding to the search string, the If statement does not return True on any of them.
Private Function GetGroups(ByVal userName As String) As Collection
Dim Groups As New Collection
Dim intCount As Integer
Dim entry As DirectoryEntry = ADEntry()
Dim mySearcher As DirectorySearcher = New DirectorySearcher(entry)
Dim arrList As New ArrayList()
' Limit the search results to only users
mySearcher.Filter = "(&(ObjectClass=User)(CN=" & userName & "))"
' Set the sort order
mySearcher.PropertiesToLoad.Add("MemberOf")
Dim searchResults As SearchResultCollection = mySearcher.FindAll()
MessageBox.Show(searchResults.Count)
If searchResults.Count > 0 Then
Dim group As New DirectoryEntry(searchResults(0).Path)
For Each member As Object In group.Properties("MemberOf")
MessageBox.Show("Pre: "+ member) 'This message box returns all the groups the user is apart of.
If group.Properties("memberOf").Contains("test-") = True Then
MessageBox.Show(member) ' This message box never shows
End If
Next
End If
Return Groups
End Function
Is there a way to apply the search or If statement again for an object where the constraint is a wildcard?
The groups I'm looking for can be around 60 (this amount increases and decreases as staff leave).
I am using VB.NET 2.0.
Thank,
Matt