从一个系统在多个系统上运行Powershell脚本

时间:2019-01-24 17:52:03

标签: windows powershell

我想将此脚本部署在Vcenter上托管的多个VM上。

https://gallery.technet.microsoft.com/scriptcenter/Install-OMS-Agent-with-2c9c99ab

上面链接中提到的脚本是用于在单个服务器上安装OMS代理的脚本。

1 个答案:

答案 0 :(得分:0)

您可以在主机名列表上使用foreach,然后在每个主机名上使用Invoke-Command

示例:

$servers = Get-Content servers.txt

foreach ($server in $servers) {
    Invoke-Command -ComputerName $server -ScriptBlock {
        .\InstallOMSAgent.ps1
    }
}
相关问题