To do this in HTML you'll need to apply styling (or preferably CSS) to the row or cell. That isn't possible with ConvertTo-Html
. It does not provide any per-row/cell formatting support. You can apply formatting to the entire table of course but that isn't sufficient.
The workaround that I've seen used is to do post-processing on the HTML to add in the styling. This can be easy or hard to do depending upon the data. For simple cases you can do string replacement. For example if you want a cell to be a different color when it has a certain value then a simple .Replace("<td>someValue</td>", "<td class=\"styleMe\">someValue</td>")
and include the CSS class as part of your pre content. If the rules are more complex then you have more work to do. For example if you wanted the entire row a different color then you'd need to parse the HTML string directly (perhaps using -Fragment
to get just the HTML table), find the cell(s) you care about and then backtrack to the find the <tr>
that marks the containing row. Not terribly difficult to do but would require a good set of helper functions and testing to get right.