Link to home
Start Free TrialLog in
Avatar of tbaseflug
tbaseflugFlag for United States of America

asked on

AD Query - Multiple Criteria

I am trying to query the department AD attribute but want to query for multiple filters - such as

department=TEST1 or department=TEST2

How would I do this>
ASKER CERTIFIED SOLUTION
Avatar of sumix
sumix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tbaseflug

ASKER

OK - this works:

deSearch.Filter = "(&(objectClass=user)(objectCategory=person)(department=APDSLN))";

But for soem reason, this does not - when I include the extra department criteria, nothing is returned - when I do one or the other, it works individually, etc. (above):

deSearch.Filter = "(&(objectClass=user)(objectCategory=person)(department=APDSLN)(department=APDSLI))";

Avatar of sumix
sumix

You use only one '&' operator, and this condition
   objectClass=user AND objectCategory=person AND department=APDSLN AND department=APDSLI
 cannot be true.

 You need to use '|' (meaning OR) operator also, this way:
deSearch.Filter = "(&(objectClass=user)(objectCategory=person)(|(department=APDSLN)(department=APDSLI)))";
   which you can translate:
    (objectClass=user) AND (objectCategory=person) AND (department=APDSLN OR department=APDSLI).