Making HTML Reports in PowerShell

You're probably aware of PowerShell's ability to make HTML output: Get-Process | ConvertTo-HTML | Out-File processes.html But did you know that the shell can do more complex reports that include multiple pieces of information? Start like this:

Don Jones

February 9, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

You're probably aware of PowerShell's ability to make HTML output:

Get-Process | ConvertTo-HTML | Out-File processes.html

But did you know that the shell can do more complex reports that include multiple pieces of information? Start like this:

$a = Get-Process | ConvertTo-HTML -Fragment 
$b = Get-Service | ConvertTo-HTML -Fragment
$c = Get-WmiObject -class Win32_OperatingSystem | ConvertTo-HTML -Fragment -Property *

Repeat that for as many bits of information as you want, putting each into a different variable. Finish up like this:

ConvertTo-HTML -body "$a $b $c" | Out-File report.html

Putting all of your variables inside those double quotes. Voila, a multi-table report. Using other parameters of ConvertTo-HTML (like -PreContent and -CssUri) you can add section headings, apply formatting, and more.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like