Powershell Get CPU Percentage
15,469
Using WMI:
get-wmiobject Win32_PerfFormattedData_PerfProc_Process | ? { $_.name -eq 'powershell' } | select name, PercentProcessorTime
Function:
function get_cpu_percentage ($id )
{
(get-wmiobject Win32_PerfFormattedData_PerfProc_Process | ? { $_.idprocess -eq $id.id }).PercentProcessorTime
}
$id4u = gps | ? {$_.id -eq 412}
get_cpu_percentage -id $id4u
Author by
Ken J
Updated on June 28, 2022Comments
-
Ken J almost 2 years
There doesn't seem to be any simple explanations on how to get CPU Percentage for a process in Powershell. I've googled it and searched here and I'm not seeing anything definitive. Can somebody explain in layman terms how to get CPU Percentage for a process? Thanks!
Here's something to get you started ;)
$id4u = gps | ? {$_.id -eq 412} function get_cpu_percentage { # Do something cool here } get_cpu_percentage $id4u
-
Ken J almost 12 yearsgps wmplayer | select cpu gives me a value of 683.484375. I'm looking for a percentage of 100%. I'm not sure how to calculate the total CPU percentage from cycles.