How to output Powershell reports in HTML?

How to output Powershell reports in HTML?

Powershell is a versatile scripting language, but viewing results in the shell can bring eye pain to some people, specially to who is accustomed to it. Using the example in the post about Powershell loops and a few additional lines in the script with the ConvertTo-Html and Out-File cmdlets, it’s possible to create a HTML file and even stylize it. This post requires previous knowledge of HTML and CSS.

Create the table code and define the elements such as the rows. Also creates an array with all the rows.

This is the table header, with the array $Array for the body of the table.

Define the CSS style for the borders.

Convert and output the file.

Open the resulting file in the default browser.

The script does take a while to process, but the end result is below.

Using the developer view inbuilt into most web browsers, its possible to inspect the outputted HTML and CSS code.

Here is the full code: