Home > PowerShell > Kill a process on remote machine using PowerShell Remoting

Kill a process on remote machine using PowerShell Remoting

In this post I will explain you how to kill a sample process on remote machine using PowerShell remoting(read my previous articles in poweshell category if you want to know more about powershell remoting). I am going to kill the process, wordpad.exe on remote machine CompB using below steps.

Establish a remote session:

$remote = New-PSSession -ComputerName CompB

Bring remote commands to local session(what the heck is this?.. see powershell blog)

Import-PSSession -Session $remote -CommandName *-Process -Prefix Remote

Verify if that process exists on remote machine

Get-RemoteProcess -Name wordpad.exe

If exists, kill it..

Get-RemoteProcess -Name wordpad.exe | stop-RemoteProcess

Hmm..Check that process is terminated on remote machine.

Happy Learning..,
Sitaram Pamarthi

  1. Carl Wayne
    April 21, 2011 at 2:59 am | #1

    Import-PSSession -Session $remote -CommandName *-Process -Prefix Remote
    gives me many lines of error…

  2. April 22, 2011 at 9:16 pm | #2

    Carl, Verify that the remote computer has PowerShell Remoting enabled.
    See my post about managing remoting feature in PS(http://techibee.com/powershell/administering-remoting-in-windows-7-powershell/541). Post the error if it continues to occur

  3. April 22, 2011 at 9:18 pm | #3

    Also refer http://techibee.com/powershell/how-to-enable-remoting-in-powershell-v2/248 for enabling remoting on remote computer to which you are trying to connect

  4. September 13, 2011 at 12:46 pm | #4

    Keep in mind this doesn’t work without an PSSession on the remote machine. There is however a way to kill remote processes without creating a PSSessions. I just wrote an article about it on my blog: http://dast-tech.tumblr.com/.

  5. Sitaram Pamarthi
    September 13, 2011 at 9:53 pm | #6

    Daryl, The link you have appended is not working. However, I guess you are using WMI to terminate a process which works fine for both XP(without PS v2) and Windows 7 environments. But if your environment is completely running with powershell V2, then I would suggest using PS remoting as it has it’s own advantages.

  1. October 1, 2010 at 10:54 pm | #1

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>