Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 290
Patrik Persson Avatar asked Nov 14 '16 09:11

Patrik Persson


People also ask

How do you force stop a process in PowerShell?

Taskkill allows you to kill a process either by its PID or by the name listed for it in the tasklist output. To stop a process by its ID, use taskkill /F /PID <PID> , such as taskkill /F /ID 312 7 if 3127 is the PID of the process that you want to kill.

How exit PowerShell command line?

To end a Windows PowerShell session in a Command Prompt window, type exit . The typical command prompt returns.

How do I kill a process in Windows?

To kill the process in Windows, you can use Task Manager, Command Prompt, or Windows Powershell. By using Task Manager, select the process and hit the “End Task” button to kill the process. You can kill the process with Command Prompt by specifying PID or Image name in the “taskkill” command.


1 Answers

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.

like image 99
Tim Haintz Avatar answered Oct 17 '22 13:10

Tim Haintz