Link to home
Start Free TrialLog in
Avatar of TxCellarRat
TxCellarRat

asked on

How can I write an ldap query to include all users from my active directory except those in a certain OU?

I'm having a debate with myself.  I'm just starting to understand LDAP Queries and wanted to pose a couple of questions because I can't seem to find the right information anywhere.

I get I can write an LDAP query that starts at the root of my Active Directory and return all the users in my AD environment.

Now..what if I want to traverse my directory and say give me all users in my Active Directory environment EXCEPT for the users in OU=Test,DC=somecity,DC=company,DC=com?

(&(objectCategory=user)(!(ou=test,dc=somecity,dc=company,dc=com)))

isn't working.  That returns all users regardless of their OU affiliation.  

Am I using the & operator incorrectly?  I also tried (what I thought was): give me all the users in the given OU...that didn't work either?

(&(objectCategory=user)(ou=test,dc=somecity,dc=company,dc=com)))

Any suggestions or assistance will be greatly apprciated!

V



ASKER CERTIFIED SOLUTION
Avatar of Mike Kline
Mike Kline
Flag of United States of America image

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
Well, if Active Directory supported extensible match, then you could do this.

http://ldapwiki.willeke.com/wiki/ExtensibleMatch

It it painful from MS documentation to determine if they do or not.
http://msdn.microsoft.com/en-us/library/cc223241(v=prot.10).aspx

-jim