I've got a very simple piece of code that is supposed to get the raw data I need to calculate number of seconds of CPU used in the last 30 seconds by any wscript process
$prev=Get-Process | Where-Object { $_.Name -eq "wscript" }
$prev
start-sleep -Seconds 30
$curr=Get-Process | Where-Object { $_.Name -eq "wscript" }
echo "section 2"
$prev
echo "section 3"
$curr
However, the values in $prev are getting reset after $curr as shown in the output below. Section 2 should be the same as the first section but it is matching the 3rd section.
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
177 19 2640 9252 1,795.55 12308 1 wscript
177 19 2628 9340 1,799.67 17316 1 wscript
177 19 2652 9292 1,803.83 25248 1 wscript
section 2
177 19 2640 9252 1,825.28 12308 1 wscript
177 19 2628 9340 1,829.42 17316 1 wscript
177 19 2652 9292 1,833.53 25248 1 wscript
section 3
177 19 2640 9204 1,825.28 12308 1 wscript
177 19 2628 9296 1,829.42 17316 1 wscript
177 19 2652 9264 1,833.55 25248 1 wscript