简体   繁体   English

使用 PowerShell 获取 CPU 百分比

[英]getting CPU percentage with PowerShell

I am trying to get the CPU usage by percent.我正在尝试按百分比获取 CPU 使用率。 I saw 2 option around but non of them work for my, both of them gave me a num that according to the task manager is not correct.我看到周围有 2 个选项,但没有一个适合我,他们都给了我一个根据任务管理器不正确的数字。

this is the two command that I tried:这是我试过的两个命令:

  1. Get-WmiObject Win32_Processor | Select LoadPercentage | Format-List

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

thanks for your help!感谢您的帮助!

Try to take the average of it.尝试取它的平均值。 Here is a link .这是一个链接

Get-CimInstance -ClassName win32_processor | Measure-Object -Property LoadPercentage -Average

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

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