Kill a process on multiple remote machines

天大地大妈咪最大 提交于 2019-12-31 03:30:48

问题


I am looking as the title says to kill a process (for example name.exe) on multiple remote machines. I can do it individually using pskill or taskkill using (for example): pskill -t \ -u -p name.exe but this becomes impractical with 50+ machines.

Is there a way to make it read a text file of IP Addresses like psexec does using the @C:\name.txt or in powershell or something similar?

All devices are on the same domain. Thank you in advance for your help.


回答1:


If you have a text file with a list of machines you could do it trivially with:

get-content serverlist.txt | Foreach-object {& pskill -t \\$_ -u -p name.exe}



回答2:


There are many methods to do this in Powershell like WMI, Invoke-command etc. Here is an example to do it using WMI:

$cred = get-credential

It will pop-up for Credential. This way you can make sure that credential is not visible in the script.

(Get-Content 'c:\Temp\Computers.txt') | ForEach-Object {
          Get-WmiObject -computer $_ -class win32_process  -filter "name = 'name.exe'" -credential $cred| %{$_.terminate()} | out-null
        }


来源:https://stackoverflow.com/questions/23161211/kill-a-process-on-multiple-remote-machines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!