Kill multiple processes running from a given path on remote machine

1.8k Views Asked by At

I have a following problem: I'm in need of a code that will close all running process from a given path on a remote machine.

So far I've found and came up with those 2 lines but none of them actually work.

Get-Process | Where-Object {$_.Path -like "\\$computername\C$\Program Files (x86)\Adobe\Adobe Reader 10.0\Reader\**"} | Stop-Process -Force    

This is the second line I've found but still does not want to work with me :)

Get-WmiObject Win32_Process -Filter "ExecutablePath LIKE '\\$computername\C$\Program Files (x86)\Adobe\Adobe Reader 10.0\Reader\'" -ComputerName $computername | Invoke-WmiMethod -Name Terminate    

I will be happy to get some advice. Belive that this is something rather simple to do..I hope that is.. :)

2

There are 2 best solutions below

1
On BEST ANSWER

Something like this should work:

(Get-WmiObject Win32_Process -ComputerName  $computerName | ?{ $_.ExecutablePath -like "*Program Files (x86)\Adobe\Adobe Reader 10.0\Reader*" }).Terminate()

You might have to tweak the "like" expression, however.

0
On

Another way to approach this is to run that command local to the machine with PSRemoting.

Invoke-Command $computername -script {
    Get-Process | Where-Object {$_.Path -like "c:\Program Files (x86)\Adobe\Adobe Reader 10.0\Reader\*"} | Stop-Process -Force  
}