如果该列的值大于100 MB,我将尝试使用红色对 RAM 列进行着色:
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}}
我尝试使用Write-Host -nonewline,但结果是错误的。
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}}