[英]Run multiple PowerShell Invoke-Command
I have been working to automate my SQL patching.我一直在努力自动化我的 SQL 补丁。 I have found that I can run the command below from my central server and it will perform the upgrade on the remote computer.
我发现我可以从我的中央服务器运行以下命令,它将在远程计算机上执行升级。 My issue is that I can only run one command at a time until the command comes back with a response.
我的问题是我一次只能运行一个命令,直到命令返回响应。 I am trying to figure out how I can run this command against 100 different computers at one time and all the upgrades can be performed at once in parallel and not one by one.
我想弄清楚如何一次对 100 台不同的计算机运行此命令,并且所有升级都可以同时并行执行,而不是一个一个执行。
Invoke-Command -computername SQLServer1 -command {D:\DBA\SQLPatching\SQL_2014\SP1\Patch-SQL2014_SP1.bat}
I would just be replacing the -computername parameter with my list of servers being patched.我只想用我正在修补的服务器列表替换 -computername 参数。
Does anyone have any suggestions?有没有人有什么建议?
Invoke-Command -ComputerName $computers -ScriptBlock {D:\DBA\SQLPatching\SQL_2014\SP1\Patch-SQL2014_SP1.bat }
Assuming that bat file is in D on all the computers.假设所有计算机上的 bat 文件都在 D 中。 Using invoke-command will run in parallel if you have a list of machines to pass to if.
如果您有要传递给 if 的机器列表,则使用 invoke-command 将并行运行。
If you instead used a ForEach $computer in $computers you would have it run one at a time.如果您改为在 $computers 中使用 ForEach $computer,您将一次运行一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.