Run commands on every node in a cluster with PowerShell

Execute commands on every node in a cluster easily with PowerShell.

John Savill

September 9, 2016

1 Min Read
Run commands on every node in a cluster with PowerShell

Q. How can I easily run commands on every node in a cluster?

A. PowerShell makes it very easy to execute commands on remote machines and remote management is enabled by default in Windows Server 2012 and above. To run a PowerShell command on every node in a cluster use the following code (replacing the cluster name and the actual PowerShell command you wish to run which in this example opens the Hyper-V Replica port).

$clusname = "savdalhv16clus"$servers = Get-ClusterNode -Cluster $clusnameforeach ($server in $servers){    Invoke-Command -ComputerName $server.Name -ScriptBlock `    {Enable-Netfirewallrule -DisplayName `    "Hyper-V Replica HTTP Listener (TCP-In)"}} 

 

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like