Invoke PowerShell commands to multiple servers at the same time
One of the best things of PowerShell is that you can invoke commands to multiple servers at once. This can save a lot of time when implementing new features or troubleshooting errors. The PowerShell Command that makes this possible is:
- Invoke-Command -ComputerName [Computername1], [Computername1] -command {[PowerShell Command here]}
In this example i have installed the Windows Clustering Feature on three different servers with the following command:
- Invoke-Command -ComputerName 2012R2-AS07, 2012R2-AS08, 2012R2-AS09 -command {Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools}
In this example i have added a Firewall rule on three different servers with the following command:
- Invoke-Command -Computername 2012R2-AS07, 2012R2-AS08, 2012R2-AS09 -command {New-NetFirewallRule -DisplayName “SQL Server Browser Service” -Direction inbound –LocalPort 1434 -Protocol TCP -Action Allow -Profile Domain}
In this example i have specified the sxs folder:
- Install-WindowsFeature –name NET-Framework-Core -source \\[Servername]\sxs -ComputerName 2012R2-AS07