Problem
You want to stop (or kill) a process on the system.
Solution
To stop a process, use the StopProcess cmdlet, as shown in Example 212.
Example 212. Stopping a process using the StopProcess cmdlet
PS >notepad PS >GetProcess Notepad
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
42 3 1276 3916 32 0.09 3520 notepad
PS >StopProcess ProcessName notepad PS >GetProcess Notepad
Example 212. Stopping a process using the StopProcess cmdlet (continued)
GetProcess : Cannot find a process with the name 'Notepad'. Verify the process name and call the cmdlet again. At line:1 char:12
+ GetProcess <<<< Notepad
Discussion
While the parameters of the StopProcess cmdlet are useful in their own right, PowerShell’s pipeline model lets you be even more precise. The StopProcess cmdlet stops any processes that you pipeline into it, so an advanced process set generated by GetProcess automatically turns into an advanced process set for the StopProcess cmdlet to operate on:
PS >GetProcess | WhereObject { $_.WorkingSet lt 10mb } | >> SortObject Descending Name | StopProcess WhatIf >> What if: Performing operation "StopProcess" on Target "svchost (1368)". What if: Performing operation "StopProcess" on Target "sqlwriter (1772)". What if: Performing operation "StopProcess" on Target "qttask (3672)". What if: Performing operation "StopProcess" on Target "Ditto (2892)". What if: Performing operation "StopProcess" on Target "ctfmon (3904)". What if: Performing operation "StopProcess" on Target "csrss (848)". What if: Performing operation "StopProcess" on Target "BrmfRsmg (1560)". What if: Performing operation "StopProcess" on Target "AutoHotkey (3460)". What if: Performing operation "StopProcess" on Target "alg (1084)".
Notice that this example uses the –WhatIf flag on the StopProcess cmdlet. This flag lets you see what would happen if you were to run the command but doesn’t actually perform the action.
For more information about the StopProcess cmdlet, type GetHelp StopProcess. For more information about the WhereObject cmdlet, type GetHelp WhereObject.