• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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.
  • 2
1 Solution
sman003Author Commented:
yep actually did, though is the filter "(anr="+ username +")" the correct filter for searching by windows login name?
I think this is the way for getting things under windows login name
see other discussions from google
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now