DirectorySearcher and Active Directory

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.
sman003Asked:
Who is Participating?
 
sman003Author Commented:
yep actually did, though is the filter "(anr="+ username +")" the correct filter for searching by windows login name?
0
 
armoghanCommented:
I think this is the way for getting things under windows login name
see other discussions from google
0
All Courses

From novice to tech pro — start learning today.