Advertisement
guyrleech

Show CPU Consumed in Given Period of Certain Processes

May 5th, 2023 (edited)
1,542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 0.82 KB | Software | 0 0
  1. ## run this line once to initialise variables otherwise 1st run of data capturing/analysis line will give errors
  2. $global:total = 0 ; $last = $null
  3.  
  4. ## run this line every time you want to see how much CPU the selected processes have consumed in total since the last run.
  5. ## note that the very first run will not return any consumption figures since there is no previous data
  6. $previous=$global:total;$global:total=0;$now=date;$now;gcim win32_process -filter "name = 'msedgewebview2.exe' and commandline like '%citrix%'"|select processid,creationdate,@{n='cpu';e={$time=($_.KernelModeTime + $_.UserModeTime)/1e7;$time;$global:total+=$time}},@{n='args';e={$_.commandline -replace '^"[^"]+"\s+'}}|sort processid|ft -auto;if( $last ) { '{0} elapsed seconds, {1} CPU seconds' -f ($now-$last).TotalSeconds,($global:total-$previous)};$last=$now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement