Occasionally it can be useful to know how to retrieve the parent, or OU holding an object, from Active Directory.
Perhaps the easiest way to do this is using the Parent property.

VbScript: Getting the OU for a user

In VbScript the value returned is a string, to get the name of the OU either connect to the object then get the name attribute or parse the name out of the string (Split, or Mid, etc). The example below shows connecting to the parent object and echoing the name.

PowerShell: Getting the OU for a user

PowerShell is a little different, the returned value is a DirectoryEntry, that means we can directly access any other property or attribute without connecting again.

Example: Getting the OU for all members of a group

These examples assume that the group path is known, no searches are involved.



The note above about Parent returning a DirectoryEntry does not apply if using the Members method in PowerShell. The object returned is a COM Object and will not work in quite the same way. This is the equivalent of the VbScript above.

1 Comment

  1. I’m so glad i found this one. Thank you so much! Even thought you wrote this 4 years ago!


Leave a Reply

Your email address will not be published. Required fields are marked *