I am using the following to search LDAP to compile a web based phone book:
However, I need to search 4 OUs. I can't for the life of me figure out how to construct the query statement to look in all four OUs. I can change it to
But that queries all of AD, yielding results I don't want. There is no common OU that I can use. How do I specify 4 OUs in the SQL statement? I've looked around and can't seem to find something that works.
Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
Code:
sQuery = "SELECT name, telephonenumber, mail, department, title, displayname, sAMAccountname "
sQuery = sQuery & "FROM 'LDAP://main-dc2/ou=Users,OU=Troy Campus,dc=mydomain,dc=org' "
sQuery = sQuery & "WHERE objectCategory='person' AND objectClass='User' "
' sQuery = sQuery & "WHERE objectClass='User' "
' If (Len(sDepartment) > 0) Then sQuery = sQuery & "AND department='" & sDepartment & "' "
If (Len(sSortBy) > 0) Then
sQuery = sQuery & "ORDER BY " & sSortBy
Else
sQuery = sQuery & "ORDER BY name"
End if
However, I need to search 4 OUs. I can't for the life of me figure out how to construct the query statement to look in all four OUs. I can change it to
Code:
sQuery = sQuery & "FROM 'LDAP://dc=mydomain,dc=org' "
But that queries all of AD, yielding results I don't want. There is no common OU that I can use. How do I specify 4 OUs in the SQL statement? I've looked around and can't seem to find something that works.
Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP