-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertHtmlTable.psm1
More file actions
35 lines (25 loc) · 1.24 KB
/
ConvertHtmlTable.psm1
File metadata and controls
35 lines (25 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function ConvertTo-ObjectToHtmlTable {
param (
[Parameter(Mandatory = $true)]
[System.Collections.Generic.List[Object]]$Objects
)
$sb = New-Object System.Text.StringBuilder
# Start the HTML table
[void]$sb.Append('<table><thead><tr>')
# Add column headers based on the properties of the first object, excluding "RowColour"
$Objects[0].PSObject.Properties.Name | Where-Object { $_ -ne 'RowColour' } | ForEach-Object { [void]$sb.Append("<th>$_</th>") }
[void]$sb.Append('</tr></thead><tbody>')
foreach ($obj in $Objects) {
# Use the RowColour property from the object to set the class for the row
$rowClass = if ($obj.RowColour) { $obj.RowColour } else { '' }
[void]$sb.Append("<tr class=`"$rowClass`">")
# Generate table cells, excluding "RowColour"
foreach ($propName in $obj.PSObject.Properties.Name | Where-Object { $_ -ne 'RowColour' }) {
[void]$sb.Append("<td>$($obj.$propName)</td>")
}
[void]$sb.Append('</tr>')
}
[void]$sb.Append('</tbody></table>')
return $sb.ToString()
}
Export-ModuleMember -Function ConvertTo-ObjectToHtmlTable