Active Directory User Group Membership

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

+3
3

, , . , CN , , CN=Test,CN=Users,DC=mydomain,DC=local, LDAP

(&(cn=test-*)(objectCategory=group)(member=CN=Test,CN=Users,DC=mydomain,DC=local))

, , LDAP-.

+1

LDAP * , , , :

(&(ObjectClass=User)(CN=" & userName & ")(memberOf=test-*))

, .

Microsoft LDAP.

+1

Verify that the group you are trying to request is a "Global Group." I had a lot of problems getting a group membership code. The only way he ever worked for me was that the group was a "global group."

0
source

Source: https://habr.com/ru/post/1759864/


All Articles