title: Modifying output for the distinguishedName in Get-ADComputer
body: <p>I'm pretty basic in my powershell knowledge. Anyway i'm trying to make a script that will convert the output from the distinguishedName in a Get-ADComputer.</p>
  
  <p>I normal case the result from querying the server with the Get-ADComputer the distinguishedName looks like this depending how the OU's is structured:</p>
  
  <pre><code>CN=&lt;servername&gt;,OU=Others,OU=Servers,OU=0180,DC=win,DC=dom,DC=&lt;something&gt;,DC=com
  </code></pre>
  
  <p>What I want to do is to convert the output into two columns and re-organize the information. So far I have got the part with two columns sorted as shown below.</p>
  
  <blockquote>
    <p>Name &emsp; ParentContainer<br>
    -------&emsp; ---------------<br>
    server1 &emsp; OU=Others,OU=Servers,OU=0180,DC=win,DC=dom,DC=,DC=com<br>
    server2 &emsp; OU=DRA8,OU=Servers,OU=Admins,DC=win,DC=dom,DC=,DC=com<br>
    server3 &emsp; OU=Others,OU=Servers,OU=0180,DC=win,DC=dom,DC=,DC=com<br>
    server4 &emsp; OU=Others,OU=Servers,OU=0180,DC=win,DC=dom,DC=,DC=com<br>
    server5 &emsp; OU=Servers,OU=4611,DC=win,DC=dom,DC=,DC=com</p>
  </blockquote>
  
  <p>the script looks like this:</p>
  
  <pre><code>$list = Get-Content "C:\temp\testservers.txt"
  foreach ($servers in $list)
  {
  Get-ADcomputer "$servers" -Properties distinguishedName,cn | 
  select name, @{n='ParentContainer';e={$_.distinguishedname -replace '^.+?,(CN|OU.+)','$1'}}
  }
  </code></pre>
  
  <p>Now to the tricky part. In the column "ParentContainer I would like to have all "DC=" values removed and then switch the OU around so instead of the above it should look like it below.</p>
  
  <blockquote>
    <p>Name &emsp; ParentContainer<br>
    -------&emsp; ---------------<br>
    server1 &emsp; OU=0180,OU=Servers,OU=Others<br>
    server2 &emsp; OU=Admins,OU=Servers,OU=DRA8<br>
    server3 &emsp; OU=0180,OU=Servers,OU=Others<br>
    server4 &emsp; OU=0180,OU=Servers,OU=Others<br>
    server5 &emsp; OU=4611,OU=Servers</p>
  </blockquote>
  
  <p>The reason for this is that it will be easier to see the OU structure and in which OU the server placed in and in a CSV file.</p>
  
  <p>Is it possible to do or am I out on deep water?</p>
  
  <p>Regards
  Torbjorn Persson</p>