header image

Some thoughts on finding a users OU

Posted by: | February 4, 2016 Comments Off on 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

under: PowerShell and Active Directory

Comments are closed.