Discussion:
DirectorySearcher .Filter settings - multiple filters?
(too old to reply)
Mark B
2008-06-08 00:44:11 UTC
Permalink
Hi,

I need to search AD for users, based on a text string entered by the Admin
in to my program.

Can I do

"(&(objectClass=user)(sAMAccountName=" & SearchString & "*)(SN=" &
SearchString & "*)(GivenName=" & SearchString & "*))"

Note that I want want to OR these search terms.

If SearchString = sAMAccountName or SN or GivenName

... then add it to the list.

What would be the syntax if I COULD do it? I'm worried about that & at the
front that might mean where object class = User AND
sAMAccountName=SearchString.

Any help appreciated.

In my previous (VB6) version, I was issuing an SQL type query. I'd prefer to
stick with pure .NET, this time around, if possible.

Mark
Mark B
2008-06-08 06:05:28 UTC
Permalink
Yay! I figured it out.

Filter = "(&(objectClass=user)(|(sAMAccountName=" & searchText & "*)(SN=" &
searchText & "*)(GivenName=" & searchText & "*)))"

Mark
Henning Krause [MVP - Exchange]
2008-06-08 08:21:14 UTC
Permalink
Hello,

note that if you want an outlook like resolution of a name, you can use
ambiguous name resolution:

(&(objectClass=user)(anr=" & searchText & "*))

Kind regards,
Henning Krause
Post by Mark B
Yay! I figured it out.
Filter = "(&(objectClass=user)(|(sAMAccountName=" & searchText & "*)(SN="
& searchText & "*)(GivenName=" & searchText & "*)))"
Mark
Loading...