- How to kill a process using TASKKILL in PowerShell?
- How to kill a process using Stop-Process in PowerShell?
Method 1: How to kill a process using TASKKILL in PowerShell?
TASKKILL is an administrator command which is used by PowerShell and CMD to kill any running process. TASKKILL uses PID (Process Identification) or the ProcessName to identify the process number and then kills it.
Syntax: To kill a Process by ID
Syntax elements are explained below.
- /F: Forcely kill the process
- PID: Specifies the process ID which is about to be terminated
Syntax: To kill a process by Name
The elements of syntax are:
- TASKKILL: used to kill a running task
- /IM: used to specify the image name of the process to be terminated
- /F: Forcely kill the process
Example
Here, we have presented the usage of the TASKKILL command which is basically used to kill a process.
If you want to get the process image name or its ID using PowerShell, you can get it via the following command:
In the above output, the first column “Image Name” represents the images present, and the second “PID” represents the process IDs, the third column “Session Name” represents services names, fourth column “Session#” tells whether the session is on or off by using 1 and 0.
Select the task you want to kill and write down its id in the command below to kill it:
From the “SUCCESS” message, it is observed that the process has been killed successfully.
TASKKILL also allows the killing of a task by specifying its name.
Specify the Name of the process you want to kill after the /IM parameter as follows:
Congratulations! You have learned to use TASKKILL to kill a process by its ID as well as by its name.
Method 2: How to Kill a process using Stop-Process in PowerShell?
The Stop-Process cmdlet is an administrative command that is used to kill the running processes. The Stop-Process command uses PID and the name to identify the process while killing.
Syntax: Kill the process by ID
Syntax elements are described as
- ID: species the ID syntax
- Force: forces the process to implement
Or
Syntax: To kill the process by name
Syntax elements are explained as
- Name: specifies the name syntax
- Force: forces the process to implement
Example
This example demonstrates the working of the TASKKILL command.
First of all, run the command of TASKLIST to get the list of tasks.
Specify the process that you want to kill and then enter its ID
Hence, the process is terminated by using the Stop-Process cmdlet.
STOP-PROCESS also allows you to kill the process by specifying its name.
The process named “notepad” is killed successfully.
Congrats! You have learned successfully to kill the process using PowerShell.
Conclusion
To kill a process, PowerShell supports Stop-Process and TASKKILL commands. Both methods trace the process either by using the process name or id. This post has provided a list of possible methods to kill a process using PowerShell. You can also get the list of the processes via the Get-Process or TASKLIST commands in PowerShell.