Platform SDK: Active Directory, ADSI, and Directory Services

Finding Objects by Class

Usually, you will want to find a specific class of objects. For example, you may want to find computers with location equal to Building 26.

(&(objectCategory=computer)(location=Building 26))

Why wasn't objectClass used? You should not use objectClass without another comparison containing an indexed attribute. Index attributes help increase the efficiency of a query. The objectClass attribute is multi-valued and not indexed. To specify the type or class of an object, you should use objectCategory instead.

//Inefficient
(objectClass=computer)
 
//More Efficient
(objectCategory=computer)

Note that there are some cases where a combination of objectClass and objectCategory must be used. The user class and contact class should be specified in the following manner:

(&(objectClass=user)(objectCategory=person))
 
(&(objectClass=contact)(objectCategory=person))

Note that you could search for both users and contacts with the following:

(objectCategory=person)