问题描述
需要在 windows powershell 中使用命令来获取 cpu 利用率前 10 名的进程。它应该像任务管理器一样返回进程名称、%cpu 和 %cpu 使用的内存顺序。
如何在 powershell 中获取此列表?
我找到了这个
Get-Counter "\Process(*)\% Processor Time" -ErrorAction SilentlyContinue `
| select -ExpandProperty CounterSamples `
| where {$_.Status -eq 0 -and $_.instancename -notin "_total","idle"} `
| sort CookedValue -Descending `
| select @{N="Name";E={
$friendlyName = $_.InstanceName
try {
$procId = [System.Diagnostics.Process]::GetProcessesByName($_.InstanceName)[0].Id
$proc = Get-WmiObject -Query "SELECT ProcessId,ExecutablePath FROM Win32_Process WHERE ProcessId=$procId"
$procPath = ($proc | where { $_.ExecutablePath } | select -First 1).ExecutablePath
$friendlyName = [System.Diagnostics.FiLeversionInfo]::GetVersionInfo($procPath).FileDescription
} catch { }
$friendlyName
}},@{N="cpu";E={($_.CookedValue/100/$env:NUMBER_OF_PROCESSORS).ToString("P")}} -First 10 `
| ft -a -HideTableHeaders
但是,以千字节为单位插入内存信息时它不起作用
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)