A PowerShell module to convert objects to HTML tables with optional row coloring.
ConvertHtmlTable provides a simple way to convert PowerShell objects into HTML table markup. It supports dynamic row coloring through a special RowColour property.
- Converts any PowerShell object collection to HTML tables
- Supports row-level CSS class styling via
RowColourproperty - Lightweight and fast using StringBuilder
- Easy one-liner installation from GitHub
Run this in an elevated PowerShell window:
iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Merit-IT/HTMLTableModule/main/ConvertHtmlTable.ps1'))- Download
ConvertHtmlTable.psm1andConvertHtmlTable.psd1 - Copy to
C:\Program Files\WindowsPowerShell\Modules\ConvertHtmlTable\1.0.0\ - Import the module:
Import-Module ConvertHtmlTable -Force
Get-Module ConvertHtmlTable -ListAvailable
Get-Command -Module ConvertHtmlTableImport-Module ConvertHtmlTable
$data = @(
[PSCustomObject]@{ Name = "Server01"; Status = "Online"; CPU = "45%" }
[PSCustomObject]@{ Name = "Server02"; Status = "Offline"; CPU = "0%" }
[PSCustomObject]@{ Name = "Server03"; Status = "Online"; CPU = "78%" }
)
$html = ConvertTo-ObjectToHtmlTable -Objects $dataOutput:
<table><thead><tr><th>Name</th><th>Status</th><th>CPU</th></tr></thead><tbody><tr class=""><td>Server01</td><td>Online</td><td>45%</td></tr><tr class=""><td>Server02</td><td>Offline</td><td>0%</td></tr><tr class=""><td>Server03</td><td>Online</td><td>78%</td></tr></tbody></table>Add a RowColour property to apply CSS classes to individual rows:
$data = @(
[PSCustomObject]@{ Name = "Server01"; Status = "Online"; RowColour = "success" }
[PSCustomObject]@{ Name = "Server02"; Status = "Offline"; RowColour = "danger" }
[PSCustomObject]@{ Name = "Server03"; Status = "Warning"; RowColour = "warning" }
)
$html = ConvertTo-ObjectToHtmlTable -Objects $dataThe RowColour property is automatically excluded from the table output and applied as a CSS class to the <tr> element.
Converts a collection of objects to an HTML table string.
| Parameter | Type | Required | Description |
|---|---|---|---|
Objects |
List[Object] | Yes | Collection of objects to convert |
String - HTML table markup
The installer automatically checks for newer versions. To update:
iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Merit-IT/HTMLTableModule/main/ConvertHtmlTable.ps1'))