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 $clusname
foreach ($server in $servers)
{
Invoke-Command -ComputerName $server.Name -ScriptBlock `
{Enable-Netfirewallrule -DisplayName `
"Hyper-V Replica HTTP Listener (TCP-In)"}
}
0 comments
Hide comments