0

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.

lightwing
  • 142
  • 1
  • 14
  • 1
    Possible duplicate of [How to colorise Powershell output of format-table](http://stackoverflow.com/questions/20705102/how-to-colorise-powershell-output-of-format-table) – Mr.Budris Dec 20 '16 at 20:09
  • Thanks. Didn't find that one when I tried searching. Still, I don't want the whole row colored, only the one "cell." If the second response in the link is accurate, then I'll just stick with wrapping the text in some form of "look at me!" text. Right now I'm settling for !!!19%!!!. – lightwing Dec 21 '16 at 20:05