I'm trying to write use a script as a workaround for a software bug for my org where the symptom is a specific PID will use endless threads. I want the script to kill a single PID (PID since there will be more than one with the process name) if it is using more than X threads. I'm testing with Chrome since it is easy to spawn multiple processes. I've been able to piece together a script for listing processes and thread usage but not sure how to then pipe/feed that into stopping the process. eg:
Get-Process -processname chrome |
Select-Object ID, @{Name='ThreadCount';Expression ={$_.Threads.Count}} |
foreach
if ($_.ThreadCount -gt 30) {stop-process -Force}
Thanks in advance