DirectorySearcher and Active Directory
Posted on 2004-10-28
Using DirectorySearcher for VB.NET and Active Directory how do I search subdirectories for a single users account?
Dim adEntry As New DirectoryEntry("LDAP://domain/OU=X,DC=X,DC=X", user, pass)
Dim adSearch As New DirectorySearcher(adEntry)
adSearch.Filter = "(SAMAccountName=" + user + ")"
Dim adResult As SearchResult = adSearch.FindOne()
When I try the above it doesn't return anything because OU has like 20 subdirectories with users in each. But if I specify "LDAP://domain/OU=Y,OU=X,DC=X,DC=X" it now will only search OU=Y and not all subfolders of OU=X...
A complete example would be appreciated.