I try to colorise the column RAM in red if the value is greater than 100 MB:
Get-Process | Format-Table @{ Label = "PID"; Expression={$_.Id}},
@{ Label = "Name"; Expression={$_.Name}},
@{ Label = "RAM (MB)"; Expression={[System.Math]::Round($_.WS/1MB, 1)}},
@{ Label = "Responding"; Expression={$_.Responding}}
I try with Write-Host -nonewline, but the result is wrong.
Get-Process | Format-Table @{ Label = "PID"; Expression={$_.Id}},
@{ Label = "Name"; Expression={$_.Name}},
@{ Label = "RAM (MB)"; Expression={write-host -NoNewline $([System.Math]::Round($_.WS/1MB, 1)) -ForegroundColor red}},
@{ Label = "Responding"; Expression={ write-host -NoNewline $_.Responding -fore red}}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…