Find User's OUs in Active Directory

Posted on 2004-11-17
Last Modified: 2012-05-05
I am trying to enumerate through the OUs a user is in. I can get the AdsPath (LDAP://CN=TestUser\, OU=Admin, OU=CompanyName, DC=testco, DC=org) for the user but I do not want to parse the path just to get the OUs (Admin, CompanyName). I will be using a Vbscript via WSH. I will be using the OUs as a criteria for code (ie. OU=Admin for the user will get a password never expires setting).

I heard from a Microsoft rep you cannot do this but I am sure someone has figured it out!

Question by:freemanjennifer04
    LVL 9

    Expert Comment

    You might check the following links: - This script is close and could likely be modified to suit your purposes.

    I would try to modify and test the second one to see if it works....just need to change the variable of what it is looking for.


    Author Comment

    This first link is what I have now for a temporary solution - parsing the AdsPath to get the OU name. The second link shows a member in the OU but I am trying to print the name of the parent container for the user the OU. I am not sure how to alter the second script to alter so that it prints distinguished name the OU the user is in...
    LVL 3

    Accepted Solution

    If you are going to be checking for certain OU's within the code itself, you could do something like this--

    If InStr(1, AdsPath, "OU=Admin", 1) > 0 Then
       'code for admin stuff
    End If
    If InStr(1, AdsPath, "OU=OTHEROU", 1) > 0 Then
       'code for other OU
    End If
    'etc etc

    That's one way to do it...
    If you truly want a list of the OU's a user is in, what's wrong with parsing AdsPath for them? (Just wondering, might help me to understand the problem a bit better)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
    Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

    737 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