diff --git a/DDUserManager/DDUserManager/ClassActiveDirectory.vb b/DDUserManager/DDUserManager/ClassActiveDirectory.vb index 59af1f0..f1e6ee3 100644 --- a/DDUserManager/DDUserManager/ClassActiveDirectory.vb +++ b/DDUserManager/DDUserManager/ClassActiveDirectory.vb @@ -9,8 +9,10 @@ Public Class ClassActiveDirectory "Dns", "Domänen-Gäste", "Domänencomput", + "Domänencontroller", "Druck", "Einstellungen eingehender", + "Erstellungen", "Ereignis", "Gäst", "Hyper-V", @@ -31,11 +33,15 @@ Public Class ClassActiveDirectory "Richtlinien-Ersteller", "SQLAccess", "Schreibgeschützte Domänen", + "Schlüsseladministratoren", "Server-Operatore", "Sicherungs", + "Storage", + "System Managed", "Terminalserver-Liz", "WinRMR", "Windows-Auth", + "Unternehme", "Zertifikat", "Zugriffssteuerungs", "Zulässige" @@ -66,52 +72,54 @@ Public Class ClassActiveDirectory Dim results As SearchResultCollection = deSearch.FindAll() For Each r As SearchResult In results Try - Dim groupName = r.GetDirectoryEntry.Name.Replace("CN=", "") + 'Dim groupName = r.GetDirectoryEntry.Name.Replace("CN=", "") + Dim groupName = r.Properties.Item("samaccountname").Item(0) If Not IsNothing(groupName) Then - Dim isValidGroup As Boolean = excludedGroupNames.Where(Function(excludedGroup) - Return Not (groupName.Contains(excludedGroup) Or groupName.StartsWith(excludedGroup)) - End Function).Any() + Dim isExcluded = excludedGroupNames.Where(Function(excludedGroup) + Return (groupName.Contains(excludedGroup) Or groupName.StartsWith(excludedGroup)) + End Function).Any() - If isValidGroup Then + If Not isExcluded Then groups.Add(groupName) End If End If - Catch + Catch ex As Exception + MsgBox("Error while fetching Active Directory groups", MsgBoxStyle.Critical) End Try Next Return groups End Function - Public Shared Function GetActiveDirectoryGroups(samAccountName As String) As List(Of String) - Dim groups As New List(Of String) - Dim adRoot As New DirectoryEntry() With { - .AuthenticationType = AuthenticationTypes.Secure - } - Dim user As DirectoryEntry = FindUser(adRoot, samAccountName) + 'Public Shared Function GetActiveDirectoryGroups(samAccountName As String) As List(Of String) + ' Dim groups As New List(Of String) + ' Dim adRoot As New DirectoryEntry() With { + ' .AuthenticationType = AuthenticationTypes.Secure + ' } + ' Dim user As DirectoryEntry = FindUser(adRoot, samAccountName) - If IsNothing(user) Then - MsgBox($"Benutzer {samAccountName} wurde nicht in der Active Directory gefunden!") - Return groups - End If + ' If IsNothing(user) Then + ' MsgBox($"Benutzer {samAccountName} wurde nicht in der Active Directory gefunden!") + ' Return groups + ' End If - user.RefreshCache(New String() {"tokenGroups"}) + ' user.RefreshCache(New String() {"tokenGroups"}) - For Each tokenGroup As Byte() In user.Properties("tokenGroups") - Dim groupName As String = GetGroupNameFromTokenGroupEntry(adRoot, tokenGroup) + ' For Each tokenGroup As Byte() In user.Properties("tokenGroups") + ' Dim groupName As String = GetGroupNameFromTokenGroupEntry(adRoot, tokenGroup) - If Not IsNothing(groupName) Then - Dim isValidGroup As Boolean = excludedGroupNames.Where(Function(excludedGroup) Not groupName.StartsWith(excludedGroup)).Any() + ' If Not IsNothing(groupName) Then + ' Dim isValidGroup As Boolean = excludedGroupNames.Where(Function(excludedGroup) Not groupName.StartsWith(excludedGroup)).Any() - If isValidGroup Then - groups.Add(groupName) - End If - End If - Next + ' If isValidGroup Then + ' groups.Add(groupName) + ' End If + ' End If + ' Next - Return groups - End Function + ' Return groups + 'End Function Public Shared Function GetActiveDirectoryUsersForGroup(groupName As String) As List(Of UserPrincipal) Dim users As New List(Of UserPrincipal)