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:
Select-Object –Property Name,ID,VM,PM,CPU |
ConvertTo-HTML –Title " Report" –CssUri http://intranet/admins/style.css |
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.
Dig Deeper on Windows administration tools
Related Q&A from Don Jones
With some simple configuration, admins can run a PowerShell script each time a computer starts with the help of the Task Scheduler GUI and cmdlets. Continue Reading
Wondering how to get PowerShell to read XML files? Our expert explains a few methods you could use. Continue Reading
There are a few methods for creating a PowerShell transcript that logs everything. We highlight a few of these and what to know about each. Continue Reading