title: Powershell: Turn list output into an array of objects or something similar using Powershell
body: <p>I know how to return hashtables, arrays etc from Powershell to c# through PSObjects. In order to use that, I need to return an object from the Powershell script - not just list the output.</p>
  
  <p>But how can I get from a list in Powershell to something structured I can return from the Powershell script?</p>
  
  <p>Think about this simple scenario (for example purposes): </p>
  
  <pre><code>Get-ChildItem C:\Test
  </code></pre>
  
  <p>And I get something like this output:</p>
  
  <pre><code>PS C:\test&gt; Get-ChildItem
  
  Directory: C:\test
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        03.06.2013     14:59          6 test1.txt
  -a---        03.06.2013     14:59          5 test2.txt
  </code></pre>
  
  <p>Now I want to take the Name and Length property of each file and return it from the powershell script as some sort of object, I can process with C#.</p>
  
  <p>An example of something I could handle from C# would be this:</p>
  
  <pre><code>$a = New-Object psobject -Property @{
     Name = "test1.txt"
     Age = 6
  }
  
  $b = New-Object psobject -Property @{
      Name = "test2.txt"
      Age = 5
  }
  
  $myarray = @()
  
  $myarray += $a
  $myarray += $b
  
  Return $myarray
  </code></pre>
  
  <p><strong>How do I get from Get-ChildItem (or something similar that gives a list) to an array of objects or something similar?</strong></p>
  
  <p>Please note that this is not about Get-ChildItem specifically, it is just used as an example of something that outputs a list.</p>