Q

How can I make my PowerShell output look better?

One of the most common PowerShell questions is how to format the output so it's more presentable. Our expert offers some insight.

How do I better format the PowerShell output?

This is a really common question, and it doesn't always have a great answer.

First of all, consider this command:

Get-Process | Select-Object –Property Name,ID,VM,PM,CPU | Format-Table

Unless you specify a format command, as I've done in this case, PowerShell's native formatting system handles the PowerShell output for any command. You will get the same capabilities, and they're fairly primitive. If you're trying to produce awesome-looking reports for the boss, lower your expectations. PowerShell isn't designed for that.

HTML lets you do a bit more:

Get-Process |
Select-Object –Property Name,ID,VM,PM,CPU |
ConvertTo-HTML –Title " Report" –CssUri http://intranet/admins/style.css |
Out-File \\intranet\wwwdocs\admins\procreport.html

This command converts the output from PowerShell to an HTML table and gives it a nice title and links to a style sheet that can provide visual formatting. Keep in mind: This approach can only take you so far. The HTML produced is pretty simplistic and, unless you start injecting JavaScript code, you can only do so much.

More robust approaches are available, and there are two free ebooks specifically on the topic. Both are listed here. One approach lets you produce HTML-based reports that can contain multiple sections, dynamic tables and much richer visual formatting. The result is still an HTML file, so it can go on an intranet Web server or be attached to an email.

The second approach inserts data into a SQL Server table (even a free Express edition) and uses SQL Server Reporting Services (also free) to produce rich heavily formatted reports. The second approach works well for trans-reports and other historical data, and it requires little programming to be successful.

About the author
Don Jones is a well-known and respected PowerShell expert and educator. He's co-author of three books on PowerShell (see PowerShellBooks.com for a list). You can find his content online, including his PowerShell Q&A forums, by visiting DonJones.com.

This was first published in April 2013

Dig deeper on Windows PowerShell Scripting

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close