Hello all,
I'm trying to create a powershell script that can monitor the CPU usage of a process.
The sample below is what I've come up with but I'm always returning a 0 value, even when getting consecutive samples.
Any help would be most appreciated. I know I have to be missing something simple...
$ProcessName = "taskmgr"
$CPUPerfCounter = New-Object System.Diagnostics.PerformanceCounter("Process","% Processor Time",$ProcessName)
$CPUTime = $CPUPerfCounter.NextValue() #/ $env:NUMBER_OF_PROCESSORS
Start-Sleep 1
$CPUTime
Start-Sleep 1
$CPUTime