使用 PowerShell 获取 CPU 百分比
我正在尝试按百分比获取 CPU 使用率。 我看到了两个选项,但它们都不适合我,它们都给了我一个数字,根据任务管理器的说法,这是不正确的。
这是我尝试过的两个命令:
Get-WmiObject Win32_Processor |选择负载百分比 |格式列表
Get-Counter -ComputerName localhost '\Process(*)\% Processor Time' ` | Select-Object -ExpandProperty 反样本` |选择对象-属性实例名称,cookedvalue` |排序对象-属性cookedvalue-降序|选择对象-前 20 ` | ft InstanceName,@{L='CPU';E={($_.Cookedvalue/100).toString('P')}} -AutoSize
感谢您的帮助!
I am trying to get the CPU usage by percent.
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.
this is the two command that I tried:
Get-WmiObject Win32_Processor | Select LoadPercentage | Format-List
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试取其平均值。这是 链接。
Try to take the average of it. Here is a link.
为了仅获取平均值,您可以使用选项“选择对象平均值”:
如果您只需要值而不是属性名称,请使用:
In order to get only the Average, you can use the option "Select-Objetct Average":
If you want only the value, not the propety name, use: