Need remote kill processes with Powershell
“I'm very new to PowerShell but at work, we would use psexec for our daily work. Now we have lost psexec. So I ask how to kill remote processes with PowerShell or if there is a script that I can use to kill processes on the remote computer. Thanks for any help.”
- Question from Reddit
How do I kill a remote computer process with Powershell on a remote computer?
Here in this post, we’ll talk about how to kill a process on a remote computer with Powershell. First of all, we should connect to the remote PC so that the way to kill processes on the remote PC will be easier.
Part 1: Connect to the remote computer
To connect to the remote PC, here we strongly recommend using AnyViewer to help you remotely access the PC with little effort and fewer limitations. With AnyViewer, you won't be limited to the same LAN. And you can get a one-click connection if you log into the same AnyViewer account on 2 devices, which can make the work or process killing be more effective. And for controling a PC from an iPad or iPhone, AnyViewer also has an iOS version.
Click on the blue button and follow me to know how to operate it.
Step 1. Install AnyViewer. Sign up for the AnyViewer account and then log in to this account on the two computers. Once logged in, the PC will be assigned to the account automatically.
Step 2. After logging in, you can see your interface in the following picture.
Step 3. On the client computer, go to "Device", locate and click the PC that you need to control. And then click "One-click control" to achieve a remote connection with one click.
Step 4. Now the connection is successfully being established.
☞Important: You can also upgrade your account to Professional or Enterprise edition to assign more devices and to connect to another computer in privacy mode.
Note: If 2 PCs are on the same network, you can also choose Remote Desktop to help you remotely access the PC. (If 2 devices are not on the same LAN, you may need to perform port forwarding with RDP.)
Step 1. Enable the Remote Desktop of remote PC
Step 2. On the local PC, search remote desktop connection in the search box and then open it.
Step 3. Enter the IP address of the remote PC and click on “Connect”.
Step 4. You’ll be asked to enter the credentials of the remote PC. Once it is accomplished, the remote connection is successful.
Part 2: Kill process with Powershell on remote PC
In this part, We’ll show you some PowerShell scripts to kill a process if it is running on a remote PC. Keep reading and take the steps into practice.
- Kill a process with Taskkill line
Step 1. On the remote PC, search Powershell and then right-click on it, choose “Run as administrator”.
Step 2. Enter the following command line:
tasklist | more
Step 3. Now you can get a list with Image Name, PID, Session Name...
Step 4. Suppose we’ll kill the “svchost.exe” program, remember the PID number of it and then run the following command line:
taskkill /F /PID 1092
Step 5. Now you’ll find that the Process “svchost.exe” is being killed successfully.
- Kill a task with Stop-process line
Actually, the basic syntax to kill a process with Powershell.
Step 1. Follow the steps above to open Powershell with the administrator and run “tasklist | more” to know the PID or the name of the program we want to kill.
Step 2. Enter the following line in Powershell (Replace process-id with the PID number of the program:
Stop-Process -ID process-id -Force
For example "Stop-Process -ID 1092 -Force"
Note: If you want to kill a process with the name, you can also choose to run the following command line to help you achieve the goal.(Replace the process-name with the image name of the process)
taskkill /IM process-name /F
For example "taskkill /IM svchost.exe /F"
In this post, we list 2 ways to kill the process with Powershell on the remote computer. After connecting to the remote PC by using AnyViewer or Remote Desktop, we can run taskkill PowerShell line or stop-process line in Powershell to help us achieve the goal.