Search code examples
powershellprocessterminate

PowerShell won't terminate hung process


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.


Solution

  • 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.