Thanks for the input, I ended up finally figuring it out. The correct format is
objCommand.CommandText = "SELECT Name, ADsPath FROM " & sADPath & _
                " WHERE objectCategory='organizationalUnit' OR objectCategory='container' AND Name='Users' ORDER BY Name"  
The AND is evauluated before the OR so this gives me all of my OU's plus the Users container.


"joe" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]

06/22/2006 11:39 AM

Please respond to
ActiveDir@mail.activedir.org

To
<ActiveDir@mail.activedir.org>
cc
Subject
RE: [ActiveDir] Complex LDAP Queries





In general SQL statements suck for LDAP queries. You should try to use LDAP for LDAP queries. First off, relatively few people use SQL format so the help is less than stellar. Second off, the SQL language has features that imply capability in LDAP queries that do not exist. Folks who are trying to work with it usually don't know much about it and tend to look at SQL help and then get confused when something doesn't work. Examples are using LIKE or multiple SORT keys and how to convert a complex LDAP query to SQL.
 
And as for Users, you are correct, it is objectclass container. That is why they call it the Users container instead of the Users OU. :) By default, every top level container under the domain NC head is a container versus an OU with the exception of Domain Controllers.
 
Anyway, a guess (yeah I don't use SQL statements either) for the proper SQL string would be something like
 
SELECT blah,blah2,blah3 FROM path WHERE blah4='blah5' OR blah6='blah7' ORDER BY blah
 
 
 
 
 
--
O'Reilly Active Directory Third Edition - http://www.joeware.net/win/ad3e.htm
 
 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent:
Thursday, June 22, 2006 10:15 AM
To:
[EMAIL PROTECTED]
Subject:
[ActiveDir] Complex LDAP Queries



I'm trying to transfrom this:

objCommand.CommandText = "SELECT Name, ADsPath FROM " & sADPath & _

               " WHERE objectCategory='organizationalUnit' ORDER BY Name"  

into this using the LDAP OR syntax from MS's scripting site:

objCommand.CommandText = "SELECT Name, ADsPath FROM " & sADPath & _

               " WHERE |(objectCategory='organizationalUnit')(objectCategory='container') ORDER BY Name"  


I'm doing this because the Users OU is really a container, not an OU. The results I get back are not at all correct.

Can anyone point out the problem with my code and/or point me in the right direction for using OR in complex LDAP queries?


Thanks,

Andrew Fidel

Reply via email to