使用 PowerShell 获取 CPU 百分比

发布于 2025-01-13 16:01:15 字数 482 浏览 1 评论 0原文

我正在尝试按百分比获取 CPU 使用率。 我看到了两个选项,但它们都不适合我,它们都给了我一个数字,根据任务管理器的说法,这是不正确的。

这是我尝试过的两个命令:

  1. Get-WmiObject Win32_Processor |选择负载百分比 |格式列表

  2. 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:

  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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城仅有旧梦在 2025-01-20 16:01:15

尝试取其平均值。这是 链接

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

Try to take the average of it. Here is a link.

Get-CimInstance -ClassName win32_processor | Measure-Object -Property LoadPercentage -Average
疏忽 2025-01-20 16:01:15

为了仅获取平均值,您可以使用选项“选择对象平均值”:

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

如果您只需要值而不是属性名称,请使用:

(Get-CimInstance win32_processor | Measure-Object -Property LoadPercentage -Average).Average

In order to get only the Average, you can use the option "Select-Objetct Average":

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

If you want only the value, not the propety name, use:

(Get-CimInstance win32_processor | Measure-Object -Property LoadPercentage -Average).Average
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文