title: How to display a user's OU using Powershell
body: <p>I'm trying to write a script that will display users specific properties, Name, Mail Address, OU respectively. the output is as intended however I can't find any solution to extract and display only the user's OU detail. when I select &quot;DistinguishedName&quot; the response is the following pattern: {CN = X, OU = Y, DC = Z}, I want to display only the OU. iv'e tried to find a method to split the DN String however no joy so far.</p>
  <p>Thanks in advance</p>
  <pre><code>Set-ExecutionPolicy Unrestricted 
  $filepath = &quot;C:\Users\Administrator\Desktop\ADusers.Csv&quot;
  $searchDomain = &quot;DC = GSDOM, DC=internal&quot;
  $adminCredential = Get-Credential
  $adSrv = 'GSDC'
  $session = New-PSSession -ComputerName &quot;$adSrv&quot; -Credential ($adminCredential)
  Invoke-Command $session -Scriptblock { Import-Module ActiveDirectory }
  Import-PSSession -Session $session -module ActiveDirectory
  Get-ADUser -Filter * -Properties * | Select-Object &quot;Name&quot;, &quot;EmailAddress&quot;, &quot;distinguishedName&quot;
  </code></pre>
  <hr />