DirectorySearcher.Filter doesnt seem to work

  • Thread starter Thread starter TheVillageCodingIdiot
  • Start date Start date
T

TheVillageCodingIdiot

Im creating a app that will go through all the OU's and look for a
certain user by username. In doing some testing I noticed that its not
filtering everything out exept for user ObjectClass. It seems to be
pulling computers as well. Not sure why this is happening but need to
limit it to just user objects. Here is the code I have.

Imports System
Imports System.DirectoryServices

Namespace ActiveDirectorySearch
Public Class ADSearch
Shared Sub main(ByVal strUserName As String)

Dim DSESearcher As New DirectorySearcher()

DSESearcher.SearchScope = SearchScope.Subtree
DSESearcher.Filter = "(objectClass=user)"

Dim objResults As SearchResult

For Each objResults In DSESearcher.FindAll()

Console.WriteLine(objResults.GetDirectoryEntry.Properties("samaccountname").Value
& "...." & objResults.GetDirectoryEntry.Path)

Next
End Sub
End Class
End Namespace
 
Ok after messing around with it I got the filter working correctly, but
it seems to be skipping some OU's. i see it search its parent OU but
some of them. for instance

Domain
-OU-a
--SubOU1
--SubOU2
--SubOU3

It will scan OU-a and all other sub ou's exept Sub2. Any Ideas
 
Back
Top