Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill processes run by a specified user in PowerShell

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?

like image 857
bigbearzhu Avatar asked Dec 05 '22 05:12

bigbearzhu


2 Answers

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.

like image 87
Keith Hill Avatar answered Dec 06 '22 18:12

Keith Hill


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 /?

like image 29
walid toumi Avatar answered Dec 06 '22 19:12

walid toumi