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
Comments on this entry are closed.
Import-PSSession -Session $remote -CommandName *-Process -Prefix Remote
gives me many lines of error…
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
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
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/.
And by that, I mean: http://dast-tech.tumblr.com/post/10157899919/powershell-kill-remote-processes-without-creating-a
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.