Powershell offers simple and straightforward methods to kill a process on a Windows computer. There are multiple ways to achieve the desired action of terminating a process on a local or remote computer. We will look at the simpler approach to ending a process by its name.
Below, we will look at two ways by which you can end a process on the local or remote computer that is running Windows operating system.
End a process using Get-Process cmdlet in Powershell
Get-Process cmdlet can be used to end a process on a computer, be it a local computer or a remote computer. Here is the command that will check if a process is running and end it with the directive shared below. In the example command below, it will find if Microsoft Paint is running on the computer. If the process is running, the Stop-process directive will kill the process.
Get-Process mspaint | Stop-Process
The command directive will end the process. But, it will not share a confirmation for it. If we are trying to end a process that is not running, we will get an error message. An alternate approach could be to first find if the process is running. If the process is found running on the computer, we can use Stop-process to end it. In this case, the sequence of commands is given below:
This command will check if mspaint is running on the computer. If mspaint is running, the command output will share its process details as displayed in the screen shot below.
Since the process is running, we can use the Get-process with Stop-process to end the process. The same command will be used to end the process as displayed in the screenshot below.
Get-Process mspaint | Stop-process
The command does not have any output, as you can see from the screenshot below.
Depending on the process you wish to check for, your Get-Process cmdlet will change the process name.
- To find if notepad is running on the computer, we can use Get-Process notepad directive.
- To find if Edge browser is running on the computer, we can use Get-Process msedge directive on the Powershell session.
- To find if Chrome browser is running on the computer, we can see Get-Process chrome directive on the computer.
Find and kill a process using ps command in Powershell
An alternate approach to ending a process is through the ps command. For our example, we will again try to end the mspaint process on a Windows 11 computer. The command for ending the mspaint process on a local Windows computer is shared below:
ps mspaint -ErrorAction SilentlyContinue | kill -PassThru
This command will do the following actions:
- it will check if mspaint process is running on the computer. If the process is found running, it will display process details on the screen. Subsequently, it will end the process.
- if the process is not found running, no output is displayed on the screen.
The screenshot below shows the command output when the mspaint process was found running. The process was subsequently killed through the command.
To end a process, Stop-process directive can be used in conjunction with the process id to kill a process. So, from the example shared above, we can modify the Stop-process directive to kill the process based on the id of the process.
Stop-process 62808 becomes the Powershell command to end the mspaint process running on the local Windows computer.
We have seen in this Powershell tutorial that a process can be killed using its name or process id. Process id can also be found through the Get-process cmdlet in Powershell. You can use the Stop-process directive to end the process based on its name or process id.
With these cmdlets, you can end a process on a local computer. For remote computers, we suggest using the PSExec command to connect to the remote computer. Once you have connected to the remote computer, you can use the same Powershell commands as you would execute on the local computer.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?
Rajesh Dhawan is a technology professional who loves to blog about smart wearables, Cloud computing and Microsoft technologies. He loves to break complex problems into manageable chunks of meaningful information.