PowerShell: Add Quorum to Clusters

# SetClusterQuorum.ps1

$clustersAndQuorums=@();
$clustersAndQuorums+=[PSCustomObject]@{ClusterName='CLUSTER1';Quorum='\\FILESHERVER007\CLUSTER1$'};
$clustersAndQuorums+=[PSCustomObject]@{ClusterName='CLUSTER2';Quorum='\\FILESHERVER007\CLUSTER2$'};

function getViableNode{
param($nodes)
foreach ($node in $nodes){
$bingo=Test-NetConnection $node -InformationLevel Quiet;
if($bingo){return $node}
}
}

function setQuorum{
param($viableNodeWithWinRM,$quorum)
write-host "Connecting to $viableNodeWithWinRM...";
$session=new-pssession $viableNodeWithWinRM;
invoke-command -session $session -scriptblock{
param($quorum)
$clustername=(Get-Cluster).Name;
write-host "Setting quorum of cluster $clustername with path $quorum.";
Set-ClusterQuorum -NodeAndFileShareMajority $quorum;
write-host "`r`nDone.`r`n----------------`r`n"
} -Args $quorum
remove-pssession $session;
}

foreach ($item in $clustersAndQuorums){
$clustername=$item.ClusterName;
$quorum=$item.Quorum;
$nodes=(Get-ClusterNode -Cluster $clustername).Name;
$viableNodeWithWinRM=getViableNode $nodes;

$validPath=Test-Path $quorum;
if($validPath){
write-host "Quorum path $quorum is valid.";
setQuorum $viableNodeWithWinRM $quorum;
}else{
write-host "Quorum path $quorum is invalid.";
}
}

Sample Output:

Quorum path \\FILESHERVER007\CLUSTER1$ is valid.
Connecting to NODE009...
Setting quorum of cluster CLUSTER1 with path \\FILESHERVER007\CLUSTER1$.

Cluster QuorumResource PSComputerName
------- -------------- --------------
CLUSTER1 File Share Witness NODE009

Done.
----------------

Quorum path \\FILESHERVER007\CLUSTER2$ is valid.
Connecting to NODE079...
Setting quorum of cluster CLUSTER2 with path \\FILESHERVER007\CLUSTER2$.
CLUSTER1 File Share Witness NODE079

Done.
----------------

Leave a Reply

Your email address will not be published. Required fields are marked *