The following statement will generate a bit html table.
ps | convertto-html
I want to make the text (or the whole line) of \"CPU(s)\" in color
You could use regex-replace with a MatchEvaluator to find the rows with values above 100
and add style="color: #FF0000;"
to the row to make the text red.
You can modify the regex + matchevaluator if you only want the CPU-value to be red by adding the color-style to the Ex. Regex-demo @ Regex101-tag for the CPU-field.
#Get HTML
$html = ps | select name, cpu, Handles, FileVersion | convertto-html
#Get headers
$headers = [regex]::Matches(($html | out-string), "
(.*?) ")
#Find index of CPU-header
$cpu = $headers | ForEach-Object -Begin { $i = 0 } -Process { if($_.Groups[1].Value -eq 'CPU') { $i } else { $i++ } }
#Regex Replace MatchEvaluator
$ME = {
param($match)
#If Group 2 (CPU) is greater than 100
if([double]::Parse($match.Groups[2].Value) -gt 100) {
#Add red text-style to row
'{0}' -f $match.Groups[1].Value
} else {
#Return org. value
$match.Value
}
}
#Regex replace all lines
$body = $html | Foreach-Object { [regex]::Replace($_, "^ ((?: [^<]*?<\/td>){$cpu} (\d.*?)<\/td><.*)", $ME) }