PowerShell won't terminate hung process

自作多情 提交于 2019-12-02 03:52:29

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/40585754/powershell-wont-terminate-hung-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!