Reputation: 21
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!
Upvotes: 2
Views: 8388
Reputation: 33
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
Upvotes: 0