I have a powershell loop that builds a table. In one of the columns, I would like to compare the number and if it's below a certain amount, display just that item in red. How can I do this? I'm building and displaying my table this way:
$mytab = ()
foreach ($1 in $all)
{
$ltr = $1.letter
$lbl = $1.label
$num = $1.number
$mytab += new-object psobject -property @{
letter = $($ltr);
label = $($lbl);
number = $($num);
}
}
$mytab | ft letter,label,number
So let's say in one iteration of my foreach loop, ($num -lt 20) is true. I want that specific instance of $num to display in the output of $mytab in red while the other columns' values are normal text color.
I can't think of any way to make write-host do this in this case, and
Am I asking too much? I realize I could probably iterate through the array, and rebuild the table a second time, but I'm hoping there's a much easier way that I'm just not aware of.
Thanks.
ETA: If not possible, I'd rather just use special characters to highlight the text than color the whole row. Right now, I'm handling this with an if statement to wrap the text in !!! characters before feeding it into the array.