Documenting Missing Security Groups in Active Directory

So in one of the environments, I am working in. There are alot of one off security groups that are undocumented in Active Directory that needs to be moved to a centralized database.
I used the following code to run through AD, Find users that have the same Dept and Job title information via the wwwHomepage attribute and compile a report to get the departments eyes on them for adding the documentation for the reasoning these groups are being added.
Should the Dept and Jobcode combination be ultimately stored in the wwwHomepage freetext field. The answer would be no but that is the way it is right now.
Dim Data As New Dictionary(Of String, Dictionary(Of String, Integer))
Dim DataSecurityCount As New Dictionary(Of String, Integer)
Dim DeptJobcode As New Dictionary(Of String, Integer)
Dim DeptJobcodeSecurityGroup As New Dictionary(Of String, Integer)
Private Sub LoadSecuritryGroupReport()
Dim enTry As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry(“LDAP://Domain.Com/DC=info,DC=sys”)
Dim mySearcher As System.DirectoryServices.DirectorySearcher = New System.DirectoryServices.DirectorySearcher(enTry)
mySearcher.Filter = “(objectCategory=person)” ‘Environment.UserName Environment.MachineName
mySearcher.PageSize = 10000
mySearcher.SizeLimit = 10000
Dim FindAll As SearchResultCollection = mySearcher.FindAll
If IsNothing(FindAll) Then
Debug.WriteLine(“Did not find user account”)
Exit Sub
End If
Dim I As Integer = 0
Dim searchResult As SearchResult
For Each searchResult In FindAll
I += 1
If searchResult.Properties.Contains(“wwwHomePage”) Then
Debug.WriteLine(searchResult.Properties(“wwwHomePage”)(0))
Debug.WriteLine(searchResult.Path)
Debug.WriteLine(searchResult.Properties(“memberof”))
If DeptJobcode.ContainsKey(searchResult.Properties(“wwwHomePage”)(0)) Then
DeptJobcode(searchResult.Properties(“wwwHomePage”)(0)) += 1
Else
DeptJobcode.Add(searchResult.Properties(“wwwHomePage”)(0), 1)
End If
If Data.ContainsKey(searchResult.Properties(“wwwHomePage”)(0)) Then
For Each MyGroup In searchResult.Properties(“memberof”)
If Data(searchResult.Properties(“wwwHomePage”)(0)).ContainsKey(MyGroup) Then
Data(searchResult.Properties(“wwwHomePage”)(0))(MyGroup) += 1
Else
Data(searchResult.Properties(“wwwHomePage”)(0)).Add(MyGroup, 1)
End If
Next
Else
Dim MyNewDictionary As New Dictionary(Of String, Integer)
For Each MyGroup In searchResult.Properties(“memberof”)
MyNewDictionary.Add(MyGroup, 1)
Next
Data.Add(searchResult.Properties(“wwwHomePage”)(0), MyNewDictionary)
End If
End If
‘End If
Next
For I = 2000 To 5 Step -1
For Each MyDict In DeptJobcode
If MyDict.Value = I Then
Debug.WriteLine(MyDict.Key & ” – ” & MyDict.Value)
For Each MyValue In Data(MyDict.Key)
For Ii = 2000 To 5 Step -1
If MyValue.Value = Ii Then
Debug.WriteLine(vbTab & MyValue.Key & ” ” & MyValue.Value)
End If
Next
Next
End If
Next
Next
Debug.WriteLine(I & ” accounts are active”)
End Sub

Leave a comment

Your email address will not be published.