AntiAffinity

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 looks like this:

Sample output

Running PSCore 6.1 and targeting one vm on a cluster:

Set

Adding new AntiAffinityGroup to the same VM:

Add

Clearing all on 'windows2016':

Clear

Setting two VMs into same AntiAffinity Group:

Set2

Summary

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!

Lego