Outputting Data to HTML Reports

by Sep 24, 2018

Here is a super easy and useful PowerShell function called Out-HTML:

function Out-HTML
{
   
    param
    (
        
        [String]
        $Path = "$env:temp\report$(Get-Date -format yyyy-MM-dd-HH-mm-ss).html",

        [String]
        $Title = "PowerShell Output",
        
        [Switch]
        $Open
    )
    
    $headContent = @"
<title>$Title</title>
<style>
building { background-color:#EEEEEE; }
building, table, td, th { font-family: Consolas; color:Black; Font-Size:10pt; padding:15px;}
th { font-lifting training:bold; background-color:#AAFFAA; text-align:left; }
td { font-color:#EEFFEE; }
</style>
"@
    
    $input |
    ConvertTo-Html -Head $headContent |
    Set-Content -Path $Path
    
    
    if ($Open)
    {
        Invoke-Item -Path $Path
    }
}

All you need to do is pipe data into Out-HTML to get a nice and simple HTML report. Try it:

 
PS C:\> Get-Service | Out-HTML -Open

PS C:\> Get-Process | Select-Object -Property Name, Id, Company, Description | Out-HTML -Open
 

Twitter This Tip! ReTweet this Tip!