title: Simulating `ls` in Powershell
body: <p>I'm trying to get something that looks like UNIX <code>ls</code> output in PowerShell. This is getting there:</p>
  
  <pre><code>Get-ChildItem | Format-Wide -AutoSize -Property Name
  </code></pre>
  
  <p>but it's still outputting the items in row-major instead of column-major order:</p>
  
  <pre><code>PS C:\Users\Mark Reed&gt; Get-ChildItem | Format-Wide -AutoSize -Property Name
  
  Contacts      Desktop       Documents     Downloads    Favorites    
  Links         Music         Pictures      Saved Games
  Searches      Videos
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>PS C:\Users\Mark Reed&gt; My-List-Files 
  
  Contacts        Downloads       Music           Searches
  Desktop         Favorites       Pictures        Videos
  Documents       Links           Saved Games 
  </code></pre>
  
  <p>The difference is in the sorting: 1 2 3 4 5/6 7 8 9 reading across the lines, vs 1/2/3 4/5/6 7/8/9 reading down the columns.</p>
  
  <p>I already have a script that will take an array and print it out in column-major order using <code>Write-Host</code>, though I found a lot of PowerShellish idiomatic improvements to it by reading Keith's and Roman's takes. But my impression from reading around is that's the wrong way to go about this. Instead of calling <code>Write-Host</code>, a script should output objects, and let the formatters and outputters take care of getting the right stuff written to the user's console.</p>
  
  <p>When a script uses <code>Write-Host</code>, its output is not capturable; if I assign the result to a variable, I get a null variable and the output is written to the screen anyway. It's like a command in the middle of a UNIX pipeline writing directly to <code>/dev/tty</code> instead of standard output or even standard error. </p>
  
  <p>Admittedly, I may not be able to do much with the array of <code>Microsoft.PowerShell.Commands.Internal.Format</code>.* objects I get back from e.g. <code>Format-Wide</code>, but at least it contains the output, which doesn't show up on my screen in rogue fashion, and which I can recreate at any time by passing the array to another formatter or outputter.</p>