简体   繁体   English

如何在PowerShell属性vm中获取兆字节的Get-Process?

[英]How to get Get-Process in PowerShell property vm in megabytes?

I'm going to write command in PowerShell, which will output my process name and virtual memory. 我将在PowerShell中编写命令,该命令将输出我的进程名称和虚拟内存。 I need to change my value vm to megabytes. 我需要将vm的值更改为兆字节。

Get-Process| Sort VM | Format-Table -p name,VM

And I have this 我有这个

Name                                                                                    VM
----                                                                                    --
Idle                                                                                     0
smss                                                                               3121152
System                                                                             6053888
AEADISRV                                                                          18485248
lsm                                                                               23670784
SearchFilterHost                                                                  24240128
svchost                                                                           27344896
svchost                                                                           27922432
wininit                                                                           31449088
svchost                                                                           34127872
armsvc                                                                            34938880
lsass                                                                             35885056
WUDFHost                                                                          36036608
csrss                                                                             36552704
winlogon                                                                          37531648
svchost                                                                           37638144

Also I need to change color if process has > 100 Mb VM 另外,如果进程具有> 100 Mb VM,我还需要更改颜色

The Format-Table cmdlet doesn't support coloring. Format-Table cmdlet不支持着色。 What you can do is to change color for each row . 您可以做的是更改每一行的颜色

If you are willing to give up the nice table format, pass the results to pipeline and use Write-Host -ForegroundColor to specify colors on cell level. 如果您愿意放弃漂亮的表格格式,请将结果传递到管道并使用Write-Host -ForegroundColor在单元级别指定颜色。 Like so, 像这样

gwmi win32_process | select name,processid,vm | % {
$params = @{ Object = $_ }
$mem = $params["Object"].VM/1MB
if([int]$mem -ge 100 ) {
    write-host -nonewline -foregroundcolor yellow $mem " "
} else {
    write-host -nonewline $mem " "
}
write-host $params["Object"].name " " $params["Object"].processid
}

Another an approach is based on saving the result on some temporary medium and add coloring later. 另一种方法是基于将结果保存在某些临时介质上,然后再添加颜色。 This requires a bit more code. 这需要更多代码。 Petri has a nice example with more code than I'm willing to copypaste here. Petri有一个很好的示例,提供了比我不愿在此处复制粘贴更多代码的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM