How to color HTML output rows

by biblo45 at 2013-02-04 07:30:25

Hi all,
I have following script:
$a = “<style>”
$a = $a + “body{color:#717D7D;background-color:#F5F5F5;font-size:10pt;font-family:‘trebuchet ms’, helvetica, sans-serif;font-weight:normal;padding-:0px;margin:0px;overflow:auto;}”
$a = $a + “a{font-family:Tahoma;color:#717D7D;Font-Size:10pt display: block;}”
$a = $a + “table,td,th {font-family:Tahoma;color:Black;Font-Size:10pt}”
$a = $a + “th{font-weight:bold;background-color:#ADDFFF;}”
$a = $a + “td {background-color:#E3E4FA;text-align: center}”
$a = $a + “</style>”
##############################
$logfile = “c:\scripts\dcdiag_all_output.log”
$allDCs = @(“xx”,“yy”,“zz”)
foreach ($item in $alldcs)

{
Dcdiag.exe /v /s:$item >> $logfile

#New-Variable “results$item” -force
#$c = $results + $item

$Results = New-Object Object
$Results | Add-Member -Type NoteProperty -Name “ServerName” -Value $item
#$TestCat = $Null
Get-Content “C:\scripts\dcdiag_all_output.log” | %{
Switch -RegEx ($)
{
#“Running” { $TestCat = ($
-Replace ".*tests on : ").Trim() }
“Starting” { $TestName = ($_ -Replace “.*Starting test: “).Trim() }
“passed|failed” { If ($_ -Match “passed”) {
$TestStatus = “Passed”


} Else
{
$TestStatus = “Failed”


} }
}


If ($TestName -ne $Null -And $TestStatus -ne $Null)
{
$Results | Add-Member -Name $(”$TestName”.Trim()) -Value $TestStatus -Type NoteProperty -force
$TestName = $Null; $TestStatus = $Null
}
New-Variable “last$item” -force -Value $results

}

}


$11 = $lastXX| ConvertTo-Html -Fragment
$22 = $lastYY | ConvertTo-Html -Fragment
$33 = $lastZZ | ConvertTo-Html -Fragment



ConvertTo-Html -head $a -Body “$11 $22 $33” -as table | out-file "C:\scripts\final.html"

Remove-Item C:\scripts\dcdiag_all_output.log


That script outputs following html output:

a user uploaded image

What i want is to mark as red for failed rows. But i could not find a proper way to achieve this. Can somebody point me?
Thanks.
by DonJ at 2013-02-04 07:37:36
You would add a class attribute, such as class=“red”, to the <td> or <tr> tags. You would then add something like .red { color:red; } to your CSS. In my free ebook on HTML reporting (www.powershellbooks.com), I actually provide a function that does this based on an expression, but you can approach it however you like.