简体   繁体   中英

getting CPU percentage with PowerShell

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!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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