【发布时间】:2013-12-20 13:50:36
【问题描述】:
如果值大于 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}}
【问题讨论】:
-
结果如何?请张贴截图。
-
阅读这篇文章,可能会有所帮助powershellmagazine.com/2013/06/20/…
-
我提供了一个答案,但它不给列着色,只是给行着色。
-
您可以对列进行不同的着色,接受的答案不再正确,您需要使用 Write-PSObject。请参阅下面的答案。
标签: powershell colors console