Kill a process on multiple remote machines

前端 未结 2 1961
别跟我提以往
别跟我提以往 2021-01-22 09:53

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): pskil

相关标签:
2条回答
  • 2021-01-22 10:06

    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}
    
    0 讨论(0)
  • 2021-01-22 10:14

    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
            }
    
    0 讨论(0)
提交回复
热议问题