Amit Geynis
Amit Geynis

Reputation: 21

cpu usage of a code block in powershell

I am trying to get Powershell to give me the average CPU usage of a code block, but can't figure out what wmi class to use.

This only gives me the current usage:

Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average

Upvotes: 2

Views: 167

Answers (1)

vonPryz
vonPryz

Reputation: 24071

The class used will return data on CPU level. Try looking at process level to get more fine-grained numbers.

The member UserModeTime contains the process' CPU time usage. A simple way to convert it into more readable values is to use TimeSpan like so, [TimeSpan]::FromMilliseconds()

Upvotes: 0

Related Questions