RatzMouze
RatzMouze

Reputation: 406

Get PID on remote computer via service name

I need to kill a process behind a service on a remote computer with PowerShell for a program/script I am creating.

The problem is that the process doesn't always have the same PID and the name is not always the same either. The only thing that always is the same is the name.

I have found out that I can get the PID of the service with this command:

taskkill /s rasmuspc /u rasmus123 /p 12345 /PID (Get-WmiObject Win32_Service|where{$_.Name -eq 'Spooler'}).ProcessID /F

I use this command to skip tasklist, so I can make it automated instead of manually looking up and typing in the PID.

But that command will only get the PID from my own computer, and I can't see is there a way to to get the PID of a service on a remote PC, only knowing the name of the service?

Upvotes: 0

Views: 7493

Answers (4)

uz-it
uz-it

Reputation: 1

To kill a corresponding process in Powershell, one line:

Get-Process -PID (Get-WmiObject -CN $RemotePCName -filter 'name="spooler"' -Class Win32_service).processID | Stop-Process -Force

Upvotes: 0

Abhi
Abhi

Reputation: 29

tasklist /s Server name. This can be used to get the list of tasks running on a remote server

Upvotes: 1

RatzMouze
RatzMouze

Reputation: 406

Taskkill /s rasmuspc /u rasmus123 /p 12345 /PID (Get-WmiObject -CN $remotepcname -filter 'name="spooler"}).processID /F

Thanks to Mathias R. Jessen, this command worked.

Upvotes: 1

polzka90
polzka90

Reputation: 123

try this

Get-Process -ComputerName "ServerName" -Name notepad | stop-Process

you need to have able in the remote machine to stop process

Upvotes: 0

Related Questions