AntiAffinity Groups in Failover Cluster. Part 4


  • Part 1 covers some theory and GUI configuration.
  • Part 2 focus on setting Preferred Owners with PowerShell.
  • Part 3 explained logic behind Possible Owners in PowerShell function.
  • Part 4 (this) will cover the last step – setting anti-affinity groups.
  • Part 5 will describe reporting of current configuration in the cluster.

    Today is a quick one – AntiAffinity groups.

    General concept

    There is no PowerShell cmdlet to set up Affinity Groups – like Set-ClusterOwnerNode. To achieve this, I must alter a class property AntiAffinityClassNames with an array of strings. Each object represents an affinity group a VM belongs to. If two VMs share the same group – cluster service will try to keep them on separate nodes.

    In short, this is all we need to check:

    $VMName = ‘Windows2016’

    (Get-ClusterGroup -Name $VMName).AntiAffinityClassNames

    And to set a simple assignment:

    (Get-ClusterGroup -Name $VMName).AntiAffinityClassNames = ‘Template’

    I’d like to be able to append new Groups if needed.

    Full Script

    Full script is available here:

    Sample output

    Running PSCore 6.1 and targeting one vm on a cluster:

    Adding new AntiAffinityGroup to the same VM:

    Clearing all on ‘windows2016’:

    Setting two VMs into same AntiAffinity Group:


    This one can help in keeping certain VMs on separate nodes (Domain Controllers, VM Guest cluster nodes, etc.)

    Next we’re going to get some reporting for every setting we’ve configured so far!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s