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 = @"
<style>
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;}
</style>
"@
$precontentheader1 = @"
<div style="padding: 20px 0 5px;position: relative;top:0px;background-color: #34495e;margin-bottom:40px;">
<center>
<img src="https://www.joseespitia.com/wp-content/uploads/2015/11/JE-white.png">
<h2 style="color:#fff; font-size:55px;">
"@
$precontentheader2 = @"
</h2>
</div>
"@

$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