LDAP Query for specific OU

Posted on 2009-04-17
Last Modified: 2013-12-24
We have an externally hosted Email Security system from Postini for Anti-Spam which allows us to push up configuration information from our AD.  

I want the initial search to be done at the Root Level of the AD tree but only want results from  a sub-OU.

Is there any way to craft an LDAP query to do this?
I.E.  When looking at the attached ADSearch.png screen shot:
Search Base = OU=AD-ROOT
BUT only show users and email addresses from OU=AD-NYC
Question by:mcarpenter1971
    LVL 70

    Accepted Solution


    A bit of a short answer I'm afraid: No.

    LDAP Queries cannot target a specific OU within the query, that can only be done by setting the search base for the query.

    There are two reasons for this. First an objects parent isn't an attribute within the object (so a users OU isn't an attribute you can query), and second, you cannot construct queries using partial distinguished names (meaning you cannot do (distinguishedName=*OU=AD-NYC ...)).

    There are of ways to work around this problem, including populating a specific attribute on the account, either with their parent OU name, or another pre-determined value. Or create a group that contains each of the users within the OU as a member and use that when making a query.

    If you would like to investigate either of those options, and want to help putting automated processes in place for it don't hesitate to ask, I'm sure we can help with that.


    Author Closing Comment

    Thanks.... That was pretty much what I was thinking.  I was told you should be able to do it but I was skeptical.  

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    A quick step-by-step overview of installing and configuring Carbonite Server Backup.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now