Prof. Powershell

Wide Load

Get a better view of the data you've asked PowerShell to fetch with the Format-Wide cmdlet.

If you've used PowerShell 1.0 for any length of time you are most likely comfortable with Format-Table and Format-List. Those cmdlets are great when you have several object properties to view. However, there may be times when you only need a single piece of information. Try this:

Get-service | Where {$_.status -eq "Running"} | Select Name

You'll end up with a long list which can be a nuisance. A better solution would be to get all the services in one screen without any scrolling. To accomplish that, use Format-Wide, which has an alias of fw. All you need to specify is a property name to display:


Get-service | Where {$_.status -eq "Running"} | format-wide Name

The default will be a two-column display which may be more than sufficient. But you can specify the number of columns:

Get-process | format-wide -column 3

Or if you prefer, you can let the cmdlet squeeze in as much information by using the -autosize parameter:

Get-process | format-wide -autosize

Like the other formatting cmdlets, you can create a complex pipelined expression:

dir $env:temp -rec | sort Extension | format-wide Name -groupby extension -autosize

This command is recursively listing the %TEMP% directory, sorting all of the files by extension. The file objects are then piped to Format-Wide, which groups the output by extension and autosizes the output. Depending on the filenames, some extensions might have three columns and some might have eight. But the end result is a concise listing without requiring you to scroll backwards through many pages.

The next time you have a lot of information to look at quickly, think wide load. For more information, look at the cmdlet's help.

About the Author

Jeffery Hicks (MCSE,MCSA,MCT) is a Microsoft MVP and an IT veteran with almost 20 years of experience, much of it spent as an IT consultant specializing in Windows server technologies. He works today as an independent author, trainer and consultant. Jeff has co-authored or authored several books, courseware, and training videos on administrative scripting and automation. His latest book is Managing Active Directory with Windows PowerShell: TFM (SAPIEN Press 2008). You can follow Jeff at twitter.com/jeffhicks and jdhitsolutions.com/blog.

Reader Comments:

Wed, Apr 22, 2009 Pat Dooley Anonymous

It is amazing that this article is necessary but unfortunately it is. The idiots that designed the language decided that pretty output is more important than giving the end user the entire data. It is too bad that such stupidity is rewarded and promoted by microsoft.

Wed, Apr 22, 2009 Brian Anonymous

Is there a cmdlet for paging? Or an option?

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above