Tuesday, February 4, 2014

querying AD using custom queries

Here is how you can use AD custom queries from querying AD objects. I wanted to query user name, email.

1. Launch Active Directory users and Computers, and select Saved Queries. Right Click Saved Queries – > new – > query

2. Give a name to the Query

3. Select the Define Query Button, Under Find select Custom Search.

After selecting Custom Search select the Advanced Tab

In the Enter LDAP query window paste the following basic query string and hit OK
(&(objectcategory=person)(objectclass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))

4. The Query will display the result

In order to extract more data follow the next step
5. Go to View and Select Add/Remove Columns ..

6. Add or remove the Columns You need

7. Right Click on the Query and select Export List


Save as a CSV.

Thanks to http://pdtechguru.wordpress.com/2012/10/15/how-to-query-active-directory-objects-3/

Also, the complete list of UAC bits:
http://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx#Examples