• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3049
  • Last Modified:

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!

1 Solution
You might check the following links:


http://www.computerperformance.co.uk/Logon/WSH_List_Members.htm - 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)


Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now