I am trying to record the load on the CPU for certain time period using PowerShell. Is there any way to record the CPU utilization in the task manager? I have tried this: Tracking CPU and Memory usage per process. But it didn't work.
Asked
Active
Viewed 1,347 times
0
-
What about: [this](http://stackoverflow.com/questions/6298941/how-do-i-find-the-cpu-and-ram-usage-using-powershell) – Jelphy May 18 '17 at 10:49
-
Thank you @Jelphy. I have tried it. It gives the current load on the CPU but i want to define the time period and get the average CPU load for that time period. – Harsh Jaswal May 18 '17 at 10:55
-
Why not use Perfmon? – vonPryz May 18 '17 at 11:08
-
Thanks @vonPryz. But none of the counters in performance monitor gives the CPU usage. – Harsh Jaswal May 19 '17 at 04:27
1 Answers
0
Use the Get-Counter
cmdlet with the SampleInterval
parameter:
$interval = 20 #seconds
$counterSample = Get-Counter '\Processor(_Total)\% Processor Time' -SampleInterval $interval
$avgLoad = $counterSample.CounterSamples.CookedValue

Mathias R. Jessen
- 157,619
- 12
- 148
- 206
-
Thanks @Mathias R. Jessen. I have tried it but I am not sure if it gives the CPU usage. The value i got here and the value in the resource monitor CPU usage is different. – Harsh Jaswal May 19 '17 at 04:30
-
How do you get an average over 20 seconds from Resource Monitor? – Mathias R. Jessen May 19 '17 at 07:46