Reputation: 1
Probably a repetitive question, but need some to-the-point answers as I'm still learning. I want to run the PowerShell script on all remote servers- simultaneously, to install an application. I tried the below cmdlet but it's executing one after the other, and also would like to know the status or job output file. Any help is much appreciated. Thanks
$servers = Get-Content "C:\Dumps\Scripts\servers.txt"
foreach ($server in $servers) {
Invoke-Command -ComputerName $server -Filepath C:\Dumps\Scripts\CompleteSilent.ps1
}
Upvotes: 0
Views: 13389
Reputation: 7057
Simply use $Servers
as the -ComputerName
argument. Invoke-Command
will run them parallel.
You can adjust the Throttle on the parallelism with the -Throttle
parameter.
Invoke-Command -ComputerName $Servers -Filepath C:\Dumps\Scripts\CompleteSilent.ps1
Note: If there are return objects and or screen echoes they may return disordered. It can be handled, but if this is an installation you may not encounter that particular issue.
Upvotes: 2