Kill processes run by a specified user in PowerShell

19,033

Solution 1

TASKKILL.EXE /FI "USERNAME eq walid" /IM myprog.exe

You can also use wildcards:

TASKKILL.EXE /FI "USERNAME eq w*" /IM m*

For more details type: taskkill.exe /?

Solution 2

V5 users can do this:

Get-Process program.exe -IncludeUserName | Where UserName -match joe | Stop-Process

The -IncludeUserName parameter requires that you are in an elevated console.

Share:
19,033

Related videos on Youtube

bigbearzhu
Author by

bigbearzhu

Updated on June 26, 2022

Comments

  • bigbearzhu
    bigbearzhu almost 2 years

    How can I kill all processes with the same name running by a specified user?

    For example, I could have multiple program.exe's running by different users. I could use:

    get-process program.exe | kill
    

    to kill all of them. But I just want to kill those instances run by a specified user. Is there a convenient way to do that?

  • bigbearzhu
    bigbearzhu over 9 years
    Good to know that, nice and simple.
  • bigbearzhu
    bigbearzhu over 9 years
    To be honest, I now like this better!
  • spuder
    spuder almost 9 years
    To make idempotent, you can check that the process is running as that user with: "(Get-Process myprog.exe -IncludeUserName ).UserName -eq 'foobar'"