Find User's OUs in Active Directory

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!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

freemanjennifer04Author Commented:
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...
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)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.