[英]Batch file or Powershell: How to Kill all Process from a particular user
I wonder how you can write a batch file or powershell script that, given an input of a user name, that it goes and kill every processes that is owned by that user. 我想知道如何编写批处理文件或Powershell脚本,在输入用户名的情况下,它会杀死该用户拥有的所有进程。
For example, if I input user name: testuser. 例如,如果我输入用户名:testuser。 I want the script to go and kill every system processes that its owner is testuser. 我希望该脚本能够杀死其所有者为testuser的每个系统进程。
On a Windows Server 2008, 2012. 在Windows Server 2008、2012上。
Thanks. 谢谢。
Using powershell
you can list all processes started by a specified user: 使用powershell
您可以列出由指定用户启动的所有进程:
Get-Process -IncludeUserName | where {$_.UserName -eq "<Username here>"}
To kill/stop a process, either call .kill()
on each result or feed the result into Stop-Process
. 要终止/停止进程,请对每个结果调用.kill()
或将结果馈入Stop-Process
。
use the command taskkill on windows server, you can kill any processes owned by specific user. 在Windows服务器上使用命令taskkill,可以杀死特定用户拥有的任何进程。
TASKKILL /F /FI "USERNAME eq " 任务/ F / FI“ USERNAME eq”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.