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:
February 9, 2011
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.
About the Author
You May Also Like