Prof. Powershell

Wide Load

See more and get more with the Format-Wide cmdlet.

In the CMD shell, I was always a big fan of the /w switch in the DIR command. This let me see a lot of files all at once by using the wide format.

I can achieve a similar result in Windows PowerShell by using the Format-Wide cmdlet:

PS C:\> dir c:\work\*.ps1 | Format-Wide

Directory: Microsoft.PowerShell.Core\FileSystem::C:\work

beg8.ps1             contest.ps1
demo.ps1             demo1.ps1
for-test.ps1         Get-SQLProfiler.ps1
jobtest.ps1          join-objectdev.ps1
junk.ps1             myscript.ps1
SQLProfiler.ps1      test-print.ps1

Unlike the CMD shell, I can take this a step further and specify the number of columns:

PS C:\> dir c:\work\*.ps1 | Format-Wide -Column 3

Directory: Microsoft.PowerShell.Core\FileSystem::C:\work

beg8.ps1          contest.ps1          demo.ps1
demo1.ps1         for-test.ps1         Get-SQLProfiler.ps1
jobtest.ps1       join-objectdev.ps1   junk.ps1
myscript.ps1      SQLProfiler.ps1      test-print.ps1

Or I can tell Format-Wide to do the best job possible using the -autosize parameter:

PS C:\> dir c:\work\*.ps1 | Format-Wide -autosize

I'll omit the results here because they probably won't format well on the page, but I will tell you I got 5 columns. The autosize and column parameters are mutually exclusive. You'll notice I didn't have to specify a property. For most objects, Format-Wide has a reasonable default assigned. But you can use anything you want.

Here's a variation:

PS C:\> dir c:\work\ | select -Property Extension -unique | sort extension | format-wide -Column 3

           .105_x64         .application
.bat       .clg             .css
.csv       .dll             .exe
.gif       .hta             .htm
.html      .InstallLog      .InstallState
.iso       .JPG             .lnk
.log       .pcv             .pdf
.pptx      .ps1             .rar
.trc       .txt             .vb
.vbs       .wav             .wim
.xml       .zip

In my Work directory I got a list of all file extensions, sorted and displayed in 3 columns. You can format any PowerShell command as wide. Here's an example that also shows how little typing is actually required by taking advantage of aliases:

PS C:\> ps | ? {$ -gt 100MB} | sort ws -des | fw -c 3

svchost         SWin         powershell_ise
powershell      firefox      WINWORD

These are the processes with a working set size of greater than 100MB.

So the next time you're tired of scrolling back to see something, remember Format-Wide.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular