VMware HA Cluster: Set-Advanced HA Settings

Recently a adjustment was made to the vCenter Cluster HA Agent timeout Settings.

Ref: https://kb.vmware.com/s/article/2017778

Performing a Reconfigure for VMware HA operation on a primary node causes an unexpected virtual machine failover

This calles for at script, because there is no way we are going to do this by hand! Feel free to use or alter the script, just remember. It is all done at your own risk.

PowerCLI Script

Function Set-HAAgentTmeout {
    param([VMware.VimAutomation.ViCore.Impl.V1.Inventory.ComputeResourceImpl][Parameter(Mandatory=$true)]$Cluster)

    if (-not $cluster.HAEnabled) {
        Write-Host "Cluster: $cluster - Does not have HA enabled"
        return
    }

    $viconnectionUid = $cluster.Uid.split('/')[1]
    $vc_connection = ""
    foreach ($viserver in $global:DefaultVIServers) {
        if ($viserver.uid -like "*$viconnectionUid*") {
            $vc_connection = $viserver
        }
    }

    # Find the correct VC Connection for delivered cluster object
    if (-not $vc_connection) {
        throw("Could not find the viconnection server")
    } else {
        $version = $vc_connection.Version.split('.')
    }

    # Get vCenter Version to set correct key
    if ($version[0] -eq 7 -And $version[2] -ge 1) {
        $key = 'das.config.fdm.unknownStateMonitorPeriod'
     } else {
        $key = 'das.config.fdm.policy.unknownStateMonitorPeriod'
     }

    $value = 30

    $option = Get-AdvancedSetting -Entity $cluster -Name $key
    $change = $false
    if ($option.count -eq 0) {
        Write-Host "Cluster: $cluster - Setting value $value"
        $null = New-AdvancedSetting -Entity $cluster -Name $key -Type ClusterHA -Value $value -Confirm:$false
        $change = $true

    } elseif ($option.value -ne $value) {
        Write-Host "Cluster: $cluster - Adjusting value $value"
        $null = $option | Set-AdvancedSetting -Value $value -Confirm:$false
        $change = $true
    } else {
        Write-Host "Cluster: $cluster - Value: OK"
    }

    if ($change) {
        Write-Host "Cluster: $cluster - Reconfiguring HA"
        $VMHosts = $cluster | Get-VMHost | Where-Object { $_.ConnectionState -eq "Connected" } | Sort-Object
        foreach ($VMHost in $VMHosts) {
            Write-Host "Cluster: $cluster - Reconfiguring Host: $VMHost"
            $VMHost.ExtensionData.ReconfigureHostForDAS()
        }
    }
}

Import-Modules VMware.PowerCLI
Connect-VIServer <you vCenter fqdn>

$clusters = Get-Cluster -Server $vcenter

foreach ($cluster in $clusters) {
    Set-HAAgentTmeout -Cluster $cluster
}
Related Post