LDAP Query for Display Name OR Description

Hello all!

So I'm looking for an LDAP query for Active Directory that will match the following requirements:

Is a User
AND has *COL* in the Display Name
OR has *BG* in the Display Name
OR has *Director* in the Office field
AND does NOT have *Directorate* in the Office field

I've gotten the first part to work with:

(&(objectcategory=person)(objectclass=user))(|(displayName=*COL *)(displayName=*BG *)(physicaldeliveryofficename=*director*))

But when I run this, it also includes anything with the word "Directorate" which I dont want.  So I tried to add "does NOT include "directorate" and I get no results:

(&(objectcategory=person)(objectclass=user))(|(displayName=*COL *)(displayName=*BG *)(physicaldeliveryofficename=*director*))(&(physicaldeliveryofficename!=*directorate*))

If I move the != around like so, I get the same info as before which includes "directorate":

(&(objectcategory=person)(objectclass=user))(|(displayName=*COL *)(displayName=*BG *)(physicaldeliveryofficename=*director*)(physicaldeliveryofficename!=*directorate*))

What am I doing wrong?
IrrylynAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
The NOT operator comes before the expression and must be outside of your OR conditional:
(&(objectClass=user)(objectCategory=person)(!physicalDeliveryOfficeName=*Directorate*)(|(displayName=*col*)(displayName=*BG*)(physicalDeliveryOfficeName=*Director*)))

Open in new window

Based on this logic reworking of the logic statement:

Is a User
AND does NOT have *Directorate* in the Office field
AND (has *COL* in the Display Name
OR has *BG* in the Display Name
OR has *Director* in the Office field)

Cheers,

Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris DentPowerShell DeveloperCommented:
Actually, I should add that some LDAP clients have a problem with the NOT syntax above, if it gets upset, try this tweak:
(&(objectClass=user)(objectCategory=person)(!(physicalDeliveryOfficeName=*Directorate*))(|(displayName=*col*)(displayName=*BG*)(physicalDeliveryOfficeName=*Director*)))

Open in new window

Chris
0
Chris DentPowerShell DeveloperCommented:
Sorry, spam... thinking about it there's another way to read the statement above. This time based on this interpretation:

Is a User
AND (has *COL* in the Display Name
OR has *BG* in the Display Name
OR (has *Director* in the Office field
AND does NOT have *Directorate* in the Office field))

(&(objectClass=user)(objectCategory=person)(|(displayName=*col*)(displayName=*BG*)(&(physicalDeliveryOfficeName=*Director*)(!physicalDeliveryOfficeName=*Directorate*))))

Open in new window


Anyway, I hope that helps :)

Chris
0
IrrylynAuthor Commented:
Aha!  Okay, I see.  I was close but I see better now how the ! works.  Thank you very much.

Both of your queries worked and gave the same results.  Very good information!
0
IrrylynAuthor Commented:
Very good tutelage.  The queries provided worked well and there was even a 'just in case' alternative.  

Great job and thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.

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.