Welcome to Sign in | Join | Help
in
Home Blog Forums

The Lazy Admin

Formatting PowerShell Output

Sponsor


PowerShell is a powerful tool that allows you to gather a large amount of data quickly and easily. A lot of times the output is spit back in a manner that is not so easy to read. Thankfully there are options available to format the output of the data.

In a previous article I showed a sample command called Get-Process which retrieved all the running processes and listed them alphabetically. Sure that might be good enough for you, but you have options. MSH includes a switch called format-list and format-table which allow you to create lists and tables of the data being output.

Get-Process | format-list

Or if you prefer your data in a table format, try this command.

Get-Process | format-table

 

Now you might look at that last example and say "Hey, that looks the same as the default output!". Well you are right, but here is where we can really customize the formatting.

Get-Process | format-table -groupby ProcessName

 

Now you can see the formatting start to come together. Let's look at one more example.

Get-Process | sort-object Id | format-table -GroupBy ProcessName

The difference in this last example is subtle, but if you look closely the data is listed by Id before being formatted into a table. These examples give you a glimpse into what formatting options you have with MSH, the power is there, you just need to harness it! Want to expand on these examples? Try the following command and see where it takes you!

Get-Command Format-*





Published Tuesday, March 21, 2006 5:46 AM by rodney.buike
Filed under:

Comments

No Comments
Anonymous comments are disabled


All postings are provided "AS IS" with no warranties, and confer no rights.
Microsoft product screen shot(s) reprinted with permission from Microsoft Corporation.