There are times when you need to kill a number of processes in one-go like today when Chrome crashed a few times hanging all the running instances – next time Google says, one tab cannot bring down all of them – send them my way :). For such times, a PowerShell script is all you need.
I wrote up a simple one which takes the process name as input and then kills all the processes which match that name.
1
2
3
4
5
6
7
8
9
| #Script is not signed, so need this. Set-ExecutionPolicy Unrestricted
#Need to set the param to a variable $target = $args\[0\]
if($target) { $orphanProcs = get-process | where {$\_.Name -eq $target}
#Check if list is null; if not kill all the procs if ($soonToBeDeadProcs) { #display list $soonToBeDeadProcs
#kill list $soonToBeDeadProcs | foreach { $\_.Kill() } } else { Write-Host "Oops, no processes found older with the name: $target" } } else { Write-Host "Oops, no arguments passed. You need to provide one argument (the Process Name)." Write-Host "Example 1: killproc chrome" Write-Host "Example 2: killproc 'some other process'" } \[/sourcecode\]
|
Example Output (Killing Chrome in this case):
PS C:\Users\amit.bahree\Desktop> .\killproc.ps1 chrome
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
\------- ------ ----- ----- ----- ------ -- -----------
139 30 34292 46708 164 3.87 376 chrome
137 22 20932 33648 149 2.48 1260 chrome
141 21 17896 31328 148 3.01 3572 chrome
5434 37 56932 66528 266 1,134.36 4940 chrome
139 22 20288 33084 150 4.12 5032 chrome
145 21 16576 31368 149 0.58 5148 chrome
147 19 14384 26992 150 1.42 5604 chrome
142 23 32292 37416 156 8.42 6528 chrome
136 17 12456 23964 142 0.30 6732 chrome
144 26 27004 39136 156 0.98 6736 chrome
1586 90 151224 209888 512 395.87 7184 chrome
138 22 21388 33916 151 3.76 7504 chrome
123 13 7756 15196 126 0.56 7512 chrome
142 21 23112 35552 150 2.01 9860 chrome
140 18 13032 25148 150 1.73 10432 chrome
|