Tuesday, 30 August 2011

Customizing HTML reports

We love to create reports using the Convertto-HTML. But sometimes I feel like it could have more style, more colors, be prettier.

That's how you do it:

$a = "<style>"
$a = $a + "TABLE{border-width: 0px;border-style: none;border-color: white;border-collapse: collapse;}"
$a = $a + "TH{border-width: 0px;padding: 0px;border-style: none;border-color: white;background-color:thistle}"
$a = $a + "TD{border-width: 0px;padding: 0px;border-style: none;border-color: white;background-color:lightblue}"
$a = $a + "</style>"

Then you just pipe the object to the cmdlet like this:

$obj | select FullName, LastWriteTime | ConvertTo-Html -head $a > C:\myfile.htm

The properties will change depending on what's your object. So change the FullName and LastWriteTime to correspond to any of the properties of your object.


No comments:

Post a Comment