Today is a quick one -
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 looks like this:
Running PSCore 6.1 and targeting one vm on a cluster:
Adding new AntiAffinityGroup to the same VM:
Clearing all on
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!