There are times where you might want to automate finding and stopping all instances of an application. Or, you want to find out which instance of an application is taking up too much resources and stop only that one.
Fortunately, there are two useful commands in Powershell that let us do just that: Get-Process and Stop-Process.
Stop-Process
To stop a process, simply specify the process name:
Stop-Process -Name <process-name>
For example:
# Stop all instances of Google Chrome
Stop-Process -Name Chrome
This will however stop all instances of the application.
But what if only want to stop a single instance of an application?
Chrome for instance, has at least as many instances as you have tabs open.
To stop a single instance, you can specify the ID:
Stop-Process -Id <process-id>
But wait, where do you get the ID? This is where Get-Process can be used.
Get-Process
To get all running processes on the system, simply type Get-Process:
Get-Process
Alternatively, to get all of the processes with the same name, you can filter down the list using -ProcessName:
Get-Process -ProcessName <process-name>
Using both together
Using our example of Chrome, we would get:
PS C:\Users\Sean> Get-Process -ProcessName Chrome
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
358 20 44408 67352 2.34 1896 1 chrome
235 16 24952 37756 8.13 1908 1 chrome
258 19 42480 58624 6.48 2064 1 chrome
288 20 47472 81420 2.09 2096 1 chrome
8469 140 272552 252188 4,913.67 2328 1 chrome
300 21 72160 112296 14.13 3132 1 chrome
356 29 115924 63600 48.20 3756 1 chrome
665 10 2728 7808 1.02 4364 1 chrome
The instance with ID 2328 seems to be taking up most of the resources. Let's stop it:
Stop-Process -Id 2328