זיו צור
זיו צור

Reputation: 21

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!

Upvotes: 2

Views: 8388

Answers (2)

Aprendiz
Aprendiz

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

Alex_P
Alex_P

Reputation: 2950

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

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

Upvotes: 2

Related Questions