Styling Your Powershell HTML Reports

When you are using Convertto-HTML, you can easily customize your reports by using the -Head, -Precontent, -Body, -Postcontent parameters.

You can insert HTML and CSS into these parameters by using a here-string.

Below is an example on how to use some of these parameters to customize an Event Log Report.

$Head = @"
body { background-color:#f6f6f6; font-family:calibri; margin:0px;}
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #34495e; color:#ffffff}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
TR:Nth-Child(Even) {Background-Color: #dddddd;}
$precontentheader1 = @"
<div style="padding: 20px 0 5px;position: relative;top:0px;background-color: #34495e;margin-bottom:40px;">
<img src="">
<h2 style="color:#fff; font-size:55px;">
$precontentheader2 = @"

$GetEventLog = Get-EventLog system -Newest 100 | Select-Object -property TimeGenerated, Source, Message, Entrytype |  Where-Object { $_.entrytype -eq "error" -or "warning" }
$Errorcount = $GetEventLog.Index.Count

$GetEventLog | ConvertTo-Html -Head $Head -PreContent "$precontentheader1 $Errorcount System Errors Found$precontentheader2" | Out-File Eventlogs.html

1 Comment

  1. Jose Espitia

    That’s great, thanks for sharing!

Leave a Reply