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: Set Virtual Machine Default Paths on Hyper-V Host of a Cluster

$newVirtualMachinePath='D:\VirtualMachines' $newVirtualHardDiskPath='D:\VirtualMachines' function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 =…

Increase Windows Management Instrumentation Service Handle Quota Limit

WMI.ps1----------------------------------------------$config = gwmi -Class "__ProviderHostQuotaConfiguration" -Namespace root$config | select -Property * -ExcludeProperty __* | ft…

PowerShell: Check TCP Connections of Server by Port Numbers

# Check-TCP-Connections.ps1# This function will output progress onto the console as well as returning a…