I'm trying to find some code that will help me query active directory and get a list of organizational units. I have some other code i was using to get the computer objects.. Now I'm trying to recode this to get OU's. Can someone please help?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Connect to AD Database
Dim rootEntry As New DirectoryEntry("GC://DC=TonyNet,DC=org", Domain.Text + userID.Text, password.Text)
'Set What you want to search for
Dim searcher As New DirectorySearcher(rootEntry)
'Set Your Search Filter
searcher.Filter = "(objectCategory=Computer)"
Dim queryResults As SearchResultCollection
queryResults = searcher.FindAll()
'Puts the results into a list Box
Dim result As SearchResult
For Each result In queryResults