Powershell脚本用于查找具有进程名称的物理内存使用情况

时间:2015-08-13 16:27:54

标签: powershell memory

我已经为CPU使用创建了一个脚本,其实例名称如下所示。任何人都可以帮我创建一个物理内存使用脚本并获取页面文件状态吗?

Get-Counter'\Process(*)\% Processor Time' | Select-Object -ExpandProperty countersamples | Select-Object -Property instancename, cookedvalue | Sort-Object -Property cookedvalue -Descending | Select-Object -First 5 | ft InstanceName,@{L='CPU';E={($_.Cookedvalue/100).toString('P')}}

InstanceName     CPU     
------------     ---     
_total           100.95 %
idle             91.74 % 
powershell_ise   4.61 %  
taskmgr          0.77 %  
coreserviceshell 0.77 % 

1 个答案:

答案 0 :(得分:0)

无法为Page文件找到一个,但这是针对内存的,根据您的代码,只需更换计数器:

Get-Counter '\Process(*)\Working Set' | 
Select-Object -ExpandProperty countersamples | 
Select-Object -Property instancename, cookedvalue | 
Sort-Object -Property cookedvalue -Descending | Select-Object -First 5 |
FT InstanceName,@{L='Memory';E={($_.Cookedvalue / 1000).toString()}}

按百分比排序:

$Total = Get-Counter '\Process(*)\Working Set' | 
Select-Object -ExpandProperty countersamples | ? {$_.instancename -eq "_total"} | Select -ExpandProperty CookedValue

Get-Counter '\Process(*)\Working Set' | 
Select-Object -ExpandProperty countersamples | 
Select-Object -Property instancename, cookedvalue | 
Sort-Object -Property cookedvalue -Descending | Select-Object -First 5 |
 ft InstanceName,@{L='Memory';E={([System.Math]::Round($_.Cookedvalue / $total * 100).toString()) + " %"}}