Inline CSS with ConvertTo-Html

The PowerShell script Get-Diskspace.ps1 uses a basic inline CSS approach to generate a more nicely HTML email from a PowerShell output.

You can use the following description for your own PowerShell script.

First, a new HTML block is configured, and the inline CSS is embedded into the head tag.

# Some CSS to get a pretty report# Variable containing the inline CSS and the full html head tag$head = @''@

The recurring data content is added to a global variable using the -Fragment attribute. This ensures that no complete HTML document data is being created.

$global:Html += $wmi | ConvertTo-Html -Fragment -PreContent "Server $($ServerName)"

Before sending the html result the full body html is generated by combinding the html fragments and the manually defined html head.

[string]$Body = ConvertTo-Html -Body $global:Html -Title "Status" -Head $headSend-Mail -From $MailFrom -To $MailTo -SmtpServer $MailServer -MessageBody $Body -Subject $ReportTitle  

Enjoy.

Entdecke mehr von Granikos GmbH & Co. KG

Jetzt abonnieren, um weiterzulesen und auf das gesamte Archiv zuzugreifen.

Weiterlesen