Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Show high CPU consumers over a given period for use when taskmgr not available
- ## properties returned by Get-Process are dynamic in that they update to latest values so we take copies to save the initial CPU used
- $timeBefore = [datetime]::Now ; $pre = ps | select id,name,cpu,ws,starttime
- ## wait for the amount of time you need to monitor or run Start-Sleep
- $timeBefore = [datetime]::Now ; $pre = ps | select id,name,cpu,ws,starttime;Start-Sleep 60;$secs = ([datetime]::Now - $timeBefore).totalseconds ; ps | % { $new = $_ ; $pre | Where { $_.id -eq $new.id -and $_.starttime -eq $new.starttime } | select id,name,@{n='CPU(s)';e={ $script:cpu = [math]::Round( $new.cpu - $_.cpu , 2 ) ; $script:cpu}},@{n='%';e={ [math]::Round( $script:cpu / $secs * 100 , 2 ) }},@{n='CPU Total (h)';e={[math]::Round($new.cpu / 3600 , 2) }},starttime} | sort '%' -desc | select -first 10|ft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement