Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill process by filename

Tags:

powershell

I have 3 instances of application running from different places. All processes have similar names.

How can I kill process that was launched from specific place?

like image 380
rpeshkov Avatar asked Apr 22 '12 06:04

rpeshkov


People also ask

Can I kill a process by name?

There are two commands we can use to kill a process by name, those being killall and pkill.

How do I kill a process in Windows by name?

To Kill Process using Process/Image Name a) Type the following command into the run prompt, to kill only the one Process, and press Enter Key. For Example - To kill Notepad, run the command as, taskkill /IM notepad.exe /F , where /F is used to kill the process forcefully.

Which command is used to kill a process by name?

There are two commands used to kill a process: kill – Kill a process by ID. killall – Kill a process by name.


2 Answers

You can get the application path:

Get-Process | Where-Object {$_.Path -like "*something*"} | Stop-Process -WhatIf 

That will work for the local machine only. To terminate remote processes:

Get-WmiObject Win32_Process -Filter "ExecutablePath LIKE '%something%'" -ComputerName server1 | Invoke-WmiMethod -Name Terminate 
like image 162
Shay Levy Avatar answered Sep 17 '22 11:09

Shay Levy


I would like to slightly improve Shay Levy's answer, as it didn't work work well on my setup (version 4 of powershell)

Get-Process | Where-Object {$_.Path -like "*something*"} | Stop-Process -Force -processname {$_.ProcessName} 
like image 36
mpasko256 Avatar answered Sep 19 '22 11:09

mpasko256