2

I have a process I'd like to kill:

$ ps Sourcetree

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
   1311     116   136720     137804      57.45   1044   1 SourceTree

Send it to Stop-Process, aka kill:

$ ps Sourcetree | kill

Runs without error. But the process isn't killed:

$ ps Sourcetree

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
   1311     116   136720     137804      57.45   1044   1 SourceTree

How can I forcibly kill a process using powershell?

2
  • 3
    stop-process -force? Commented Apr 7, 2017 at 20:56
  • @4c74356b41 For some reason the docs I found doesn't include the -force, but you're right - list that as an answer (with a link to msdn.microsoft.com/en-us/powershell/reference/5.1/…) and I;ll mark it as correct. Commented Apr 7, 2017 at 22:52

4 Answers 4

2

The simplest correct answer is:

Get-Process SourceTree | Stop-Process -Force

"SourceTree" is a process name.

Sign up to request clarification or add additional context in comments.

1 Comment

I originally marked the answer using Unix-style aliases as correct, but given the question title, this one is probvably better.
1

if you do it?

(get-process -Name SourceTree).Kill()

1 Comment

Doesn't kill it. I needed -force per accepted answer above.
0

To better understand cmdlets and what they do you can always do Get-Help cmdlet and look what it does\supports.

Get-Help Stop-Process

or just enter the cmdlet into the search engine, that will most likely lead you to a official help article.

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/stop-process

Comments

0

Use -Force.

ps -force Sourcetree | kill

Taken from help Stop-Process -online

Stop-Process [-Id] <Int32[]> [-PassThru] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

-Force

Stops the specified processes without prompting for confirmation.
By default, Stop-Process prompts for confirmation before stopping
any process that is not owned by the current user.

To find the owner of a process, use the Get-WmiObject cmdlet to
get a Win32_Process object that represents the process, and then
use the GetOwner method of the object.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: 

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Bonus nachos, Get-Command -ParameterName *force will show all Cmdlets that include the force param.

3 Comments

I don't think this is equivalent to taskkill /f, or "kill -9" in unix. There doesn't seem to be a straightforward way.
I think that -force parameter goes for the Kill cmdlet, not for ps (Get-Process) ps Sourcetree | kill -force
If you write up someone else's comment as an answer, (a) give credit where it's due and (b) test the example to make sure it's correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.