PowerShell.com

Join PowerShell.com!
PowerShell eBook
Script Library
Video Library
Meet Dr. Tobias Weltner


PowerShell eBook
Sign up for
Your PowerTip of the Day:

PowerShellPlus Upgrade Now


PowerShellPlus


Membership Privileges


Monthly Membership Prizes

Winner Aleksandar Nicolic (Dec.)
Thomas Lee (Nov.)

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Here you'll find resources dedicated to helping you learn and master PowerShell along with forums for communicating with your PowerShell Peers. Here is a quick overview of all that PowerShell.com provides:

Tobias' Tip of the Day               All PowerTips

Outputting HTML Reports

PowerShell can export results as HTML. Simply pipe the results to ConvertTo-HTML and save the result in a file. When you do that, it is wise to use Select-Object to first limit the object properties to only those you want to see in your report, otherwise your HTML table gets huge.

Get-Service | Select-Object Status, Name, DisplayName | ConvertTo-HTML | Out-File report.htm
.\report.htm

The resulting report is a bit ugly, though. With the help of the optional parameters, -title, -body and -head, you can add colors, fonts and other design information. The most important customizing parameter is -head, allowing you to define styles for the different HTML elements in your report.

$head = @'<style>
BODY{font-family:Verdana; background-color:lightblue;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{font-size:1.3em; border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#FFCCCC}
TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:yellow}
</style>'@

$header = "<H1>Reporting Service Status</H1>"
$title = "Example HTML Output"

Get-Service |
Select-Object Status, Name, DisplayName |
ConvertTo-HTML -head $head -body $header -title $title |
Out-File report.htm
.\report.htm
Copyright 2008 PowerShell.com. All rights reserved.