You may want to kill a Windows Process on a remote computer for many reasons. Thanks to PowerShell, this task can be performed easily using the Get-WmiObject cmdlet.
- First, use the Get-WmiObject cmdlet to get the process
- Next, use the “terminate()” function to kill the process.
[cmdletbinding()] param( $ComputerName=$env:COMPUTERNAME, [parameter(Mandatory=$true)] $ProcessName ) $Processes = Get-WmiObject -Class Win32_Process -ComputerName $ComputerName -Filter "name='$ProcessName'" foreach ($process in $processes) { $returnval = $process.terminate() $processid = $process.handle if($returnval.returnvalue -eq 0) { write-host "The process $ProcessName `($processid`) has been terminated successfully." } else { write-host "The process $ProcessName `($processid`) has not been terminated." } }
In order to use this script, save it as “Kill-RemotelyProcess.ps1” and run the following command:
PS > Kill-RemotelyProcess.ps1 -ComputerName <FQDN_Computer> -ProcessName <Name_of_the_process>
Thanks for reading! You can follow me on Twitter @PrigentNico