This is very handy if you have a hung (non-responsive) process that you need to terminate.
The Old Way
Using conventional methods, you might pull up Windows Task Manager, identify your hung process in the long list of Image Names within the “Processes” tab, right-click the process and select “End Process”. From there you might have to wait quite a while for Windows to actually do the termination.
The PowerShell Way
The PowerShell method is much quicker especially if you know the name of the process to be terminated. There are two steps involved: (1) identify the process ID(s) of program to be terminated and (2) stop the running process(es). The associated PowerShell cmdlets are “Get-Process” and “Stop-Process” (or their convenient Unix-Shell aliases “ps” and “kill”.
Example
For this example, let’s say that your Internet Explorer web browser has become unresponsive and you need to terminate it (not that that would ever happen in real life). Here are our two steps in action:
(1) Identify the process(es) using Get-Process (or in this case I will use the shorter alias “ps”). This is very easy if you know at least part of the process name that you’re looking for. In this case, I happen to know that the process name for Internet Explorer is “iexplore”. For this example, I’ll just find all processes that start with “iex” as follows:
|
1 2 3 4 5 |
PS C:\powershell> ps |? {$_.processname -like "iex*"} Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 563 15 28548 33984 152 2.05 2964 iexplore 388 12 7608 15840 91 0.75 3296 iexplore |
|
1 |
PS C:\powershell> kill 2964,3296 |
Also, these will work:
ps iex* | kill
or
kill -name ie*