Posted On February 8, 2020

PowerShell: Add Quorum to Clusters

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

PowerShell: Export Event Logs by a Certain Date Range

# User defined variables $daysLimit=7 $startdate=(get-date).adddays(-$daysLimit) $computername=$env:computername $logName='Application' $filterTypes='Error','Warning' $logPath="c:\temp\eventlogs-from-$($startdate.tostring('yyyy-MM-dd'))-to-$((get-date).tostring('yyyy-MM-dd')).csv" # Get the event logs…

PowerShell: Download and Apply Windows Patch KB

The following snippet assumes that a Windows machine has access to download Microsoft patches directly…

PowerShell: File Copying Operation

2/11/20 Update: Version 0.1.8 is available here: https://blog.kimconnect.com/powershell-file-copy-script-using-emcopy-vss-legacy/ Version 0.1.6 <#.Description File_Copy_Script Version: 0.16Purpose: this…