Some thoughts on finding a users OU

Back in this post http://itknowledgeexchange.techtarget.com/powershell/discovering-a-users-ou/

I showed how to get the OU of a user from the distinguished name of the user object. if you want to display that as part of your output you can create a calculated field

Get-ADUser -Filter * -Properties DisplayName |
select Name, DisplayName, UserPrincipalname, @{N= “Organanisational Unit” ;
E = {($_.DistinguishedName -split ‘,’, 2)[1]}}

In your select statement take the Distinguishedname and split it on the comma – make sure you split it into 2 parts – the second is the OU

Don’t rely on the Displayname alone as its not present for some built in accounts such as administrator

Advertisements
This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

2 Responses to Some thoughts on finding a users OU

  1. James says:

    How would you do this if the user’s name is in the Last comma First format?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s