Automatically move clustered applications to their default preferred owner

Ever had to restart several nodes of a cluster? What do you do with the clustered resources after all nodes are back up again? Right, you redistribute them. Tedious work if we’re talking about really big clusters with many clustered resources.

Fortunately, PowerShell can help here. I’ve created a custom script that will automatically redistribute the resources. For that to work, each resource needs to have a preferred owner:

The script that will do the work:

Import-Module FailoverClusters
 
$clustergroups = Get-ClusterGroup | Where-Object {$_.IsCoreGroup -eq $false}
foreach ($cg in $clustergroups)
{
    $CGName = $cg.Name
    Write-Host "`nWorking on $CGName"
    $CurrentOwner = $cg.OwnerNode.Name
    $POCount = (($cg | Get-ClusterOwnerNode).OwnerNodes).Count
    if ($POCount -eq 0)
    {
        Write-Host "Info: $CGName doesn't have a preferred owner!" -ForegroundColor Magenta
    }
    else
    {
        $PreferredOwner = ($cg | Get-ClusterOwnerNode).Ownernodes[0].Name
        if ($CurrentOwner -ne $PreferredOwner)
        {
            Write-Host "Moving resource to $PreferredOwner, please wait..."
            $cg | Move-ClusterGroup -Node $PreferredOwner
        }
        else
        {
            write-host "Resource is already on preferred owner! ($PreferredOwner)"
        }
    }
}
Write-Host "`n`nFinished. Current distribution: "
Get-ClusterGroup | Where-Object {$_.IsCoreGroup -eq $false}

3 thoughts on “Automatically move clustered applications to their default preferred owner

  1. Great script! As a powershell novice, this saved me a ton of work. I added -Cluster to make a remote call to another server. That helps for when we patch our servers and have multiple clusters to work on. Thanks again!

  2. Pingback: Windows Cluster patchen und automatisch Verteilung wieder herstellen - SQL aus Hamburg - 1

Leave a Reply

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