10

I have a scenario where a process is stuck every single Monday morning because of an Oracle database so I tried creating a PowerShell script to run every Monday but regardless of getting an error or not, the process remains.

The line I'm attempting to use for the "kill" is:

Get-Process -Name ez0* -ComputerName $server | Stop-Process -Force

Tried doing this locally as well without the -ComputerName.

I'm not getting any errors from this line with or without the -Force it just executes and moves on.

Just doing Get-Process works and I can see it but I can't end it with PowerShell. After many attempts I remotely logged on to the server and just right-clicked the process and chose "End task" which worked just fine.

It is an odd process because it's one out of initial 8 (based on cores) and when you stop the service, all but one of the processes is removed save for the one that is hung.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Patrik Persson
  • 173
  • 1
  • 2
  • 15
  • 1
    try ``Invoke-Command $server -Scriptblock {Get-Process -name ez0* | Stop-Process -Force}`` – 4c74356b41 Nov 14 '16 at 09:50
  • Using version 5+, I get following exception when trying to stop a process object from a remote server passed through the pipeline: `stop-process : Cannot stop process "notepad (11720)" because of the following err or: Feature is not supported for remote machines.` – Lieven Keersmaekers Nov 14 '16 at 11:39
  • I will attempt the wmi way on Monday to see how things go but this is not a remote issues wince the local test was the same. – Patrik Persson Nov 14 '16 at 15:16

1 Answers1

14

Try using:

$termproc = (get-wmiobject -ComputerName $server -Class Win32_Process -Filter "name like 'ez0%'"
$termproc.terminate()

You could also just do the below if you don't want to check the processes in the variable first.

(get-wmiobject -ComputerName $server -Class Win32_Process -Filter "name like 'ez0%'").terminate()

Thanks, Tim.

Tim Haintz
  • 628
  • 1
  • 6
  • 9