Powershell Tip #124: Extract the OU (Organizational Unit) from DN (Distinguished Name) in Active Directory

By | October 23, 2016

Tip: You can extract the OU (Organizational Unit) from DN (Distinguished Name) in Active Directory.

For example, someone sent you one report with DN only and you need to extract the OU.

extract-ou-from-dn-powershell


previous-buttonnext-button

2 thoughts on “Powershell Tip #124: Extract the OU (Organizational Unit) from DN (Distinguished Name) in Active Directory

  1. Pingback: Powershell Tip #125: Identify the duplicates headers of a CSV file | Powershell Guru

  2. Matt Brown

    Nice,

    I recommend the regex with the following upgrade that will work regardless of if the object is in an OU or Container

    [regex]::match($distinguishedName,'(?=OU|DC|CN)(.*\n?)(?<=.)').Value

    Reply

Leave a Reply

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