HTML
HTML is frequently used in PowerShell as a means of generating reports by email. PowerShell includes ConvertTo-Html
, which may be used to generate HTML content.
ConvertTo-Html
ConvertTo-Html
generates an HTML document with a table based on an input object. The following example generates a table based on the output from Get-Process
:
Get-Process |
ConvertTo-Html -Property Name, Id, WorkingSet
Multiple tables
ConvertTo-Html
may be used to build more complex documents by using the Fragment
parameter. The Fragment
parameter generates an HTML table only (instead of a full document). Tables may be combined to create a larger document:
# Create the body
$body = '<h1>Services</h1>'
$body += Get-Service |
Where-Object Status -eq 'Running' |
ConvertTo-Html -Property Name, DisplayName -Fragment
$body += '<h1>Processes</h1>'
$body += Get-Process |
Where-Object WorkingSet -gt 50MB |
ConvertTo-Html -Property Name, Id, WorkingSet-Fragment
# Create a document with...