0

I am trying to kill all processes on a terminal server for a specific user, but I want to have 2 or more processes not killed. I am unsure on how to filter multiple Imagenames that are not equal?

I have previously tried using -and or declaring /FI "Imagename ..." again and did not then filter any of them

taskkill.exe /F /FI "USERNAME eq bot1" /FI "IMAGENAME ne Code.exe" /FI "IMAGENAME ne OUTLOOK.EXE"

I would expect this to close everything apart from the two items stated but this still closes all of them. If I delete the second instance of "IMAGENAME" it runs and does not close Code.exe as stated. How can I have exceptions of processes, I do not want closed?

jradich1234
  • 1,410
  • 5
  • 24
  • 29

1 Answers1

0

Taskkill isn't powershell. You can try stop-process.

get-process -IncludeUserName | 
  where-object { $_.username -eq 'bot1' -and $_.name -ne 'code' -and
  $_.name -ne 'outlook' } | stop-process -whatif
js2010
  • 23,033
  • 6
  • 64
  • 66
  • Thanks i have used something like this before in where i also included ComObjects too, but Taskkill works within Powershell when i specify just one item to not kill, this will be an invoked powershell script by uipath on a terminal server without effecting other users – Bloodrusher123 May 08 '19 at 19:44
  • @deadrobot that suggested edit will not exclude those two processes. – js2010 May 09 '19 at 12:33