Liefert eine Liste zurück mit allen Gruppen zu denen ein Benutzer gehört.
Imports System.DirectoryServices
Imports System.DirectoryServices.ActiveDirectory
Public Function GetUserMemberOf(ByVal domain As String, ByVal username As String, ByVal password As String, Optional ByRef exeption As Exception = Nothing) As Collections.Generic.List(Of String)
Dim searcher As DirectorySearcher = Nothing
Dim colEntry As New Collections.Generic.List(Of String)
Try
searcher = New DirectorySearcher(New DirectoryEntry("LDAP://" & domain, username, password))
searcher.Filter = String.Concat("(&(objectClass=User) (sAMAccountName=", username, "))")
searcher.PropertiesToLoad.Add("MemberOf")
Dim result As SearchResult = searcher.FindOne
For i As Integer = 0 To result.Properties("MemberOf").Count - 1
Dim sProp As String = result.Properties("MemberOf")(i)
colEntry.Add(sProp.Substring(3, sProp.IndexOf(",") - 3))
Next
Catch ex As Exception
exeption = ex
Finally
searcher.Dispose()
End Try
Return colEntry
End Function
1 Kommentare zum Snippet