How To Kill Windows Process Using Powershell

Windows

On windows server, whenever we start any application like SAP or Database, operating system creates a process for an executable file.
Windows assign the PID (process Id) which is unique identification to each process.

As an administrator you might need to kill a process at multiple instances.

Although there are multiple ways to perform this task like using task manager or command prompt with taskkill command,Today in this article we will discuss how we can use Powershell to kill the windows process.

  • Open Powershell with user with admin rights.
  • To get the list of processes running on the server, enter the command
Get-Process

Output will be displayed as below:

PS C:\Users\username> Get-process

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    445      20     9392       5680       2.45   8900   1 AcroRd32
    512      55    46588      11444      16.75  18328   1 AcroRd32
    595      33    31516      27800       6.17   6504   1 ApplicationFrameHost
    456      62    14064       6724              4220   0 AppVClient
    322      25    47084      11988       2.58   2736   1 AppVStreamingUX
    149       9     1608       1348              4012   0 armsvc
    700      26    92364      89204   1,940.78  24608   0 audiodg
    166      10     4640       4328       0.09  24832   1 bash
  2850      48    44800      41692      53.22  32396   1 ShellExperienceHost
    205      11     2440       2824              2424   1 shtctky
    894      23    14080      29184      62.22   7524   1 sihost
     52       3      508        308               420   0 smss
    699      40    19064      28480      46.53  12204   1 SnippingTool
    179      13     4452       5920       0.06  33428   1 splwow64
    442      22     6872       6268              4052   0 spoolsv
    125       9     3956       3244       0.02  34464   1 ssh-pageant
    404      11     3760       5012               456   0 svchost
   1512      18    11228      12516               504   0 svchost
     84       5     1088       1172               940   0 svchost
   1067      25    18012      23468               972   0 svchost
    499      19     4836       4396              1288   0 svchost
    148       9     2000       2240              1296   0 svchost
    196      12     1912       3048              1308   0 svchost
    173      47     9664       3664              1316   0 svchost
    211       9     2420       3636              1428   0 svchost
    193      12     2320       4464              1488   0 svchost
    238      14     3888       4956              1496   0 svchost
    152       9     2308       4388              1504   0 svchost
    120       9     1764       1784              1672   0 svchost
    565      34    11340      10720              1744   0 svchost
    490      14    17580      11568              1752   0 svchost
    178      10     1888       2108              1904   0 svchost
    388      18     5368       8620              1948   0 svchost
    190       9     1852       2544              2364   0 svchost
    414      18     7404       9704              2376   0 svchost
    161      45     2268       2364              2420   0 svchost
    853      11     4432       5976              2448   0 svchost
    274      15     3428       4128              2552   0 svchost
    207      12     2248       2964              2656   0 svchost
    296       7     1552       1636              2692   0 svchost
    213      11     2780       5084              2700   0 svchost
    446      10     3320       4592              2708   0 svchost
    310      10     3232       5024              2752   0 svchost
    175      10     1976       3500              2800   0 svchost
    158       9     1936       3224              2820   0 svchost
    248      15     2616       2492              2904   0 svchost
    445      22     8096      21768      22.17   2916   1 svchost
    208      14     2348       4904              2952   0 svchost
    214      12     2940       4968              2976   0 svchost
    242      13     4592       7528              3016   0 svchost
   1951      20    33180      28188              3116   0 svchost
    450      19     3564       6048              3208   0 svchost
    432      14     4204       8448              3308   0 svchost

Now suppose we need to kill the process SnippingTool, we will kill the process by it’s process ID.

Here PID for SnippingTool is 12204, we can use below comdlet to kill the process.

Stop-Process -ID PID -Force

In our case,
Stop-Process -ID 12204 -Force

If we need to kill process by it’s name, use below command:

Stop-Process -Name "ProcessName" -Force

In our case,
Stop-Process -Name "SnippingTool" -Force