Hi everyone,

In Hyper-V there is an option where you can have a virtual cluster (using shared disks or using virtual fibrechannel. But what would happen to the cluster if they are running on the same server that would crash. At those moments, the entire “failover cluster” is not used anymore, and thus the service becomes unavailable for a longer time then “expected”.

The solution on this, is to create a group for this using the AntiAffinityCollection value in the virtual machine.

First make sure that you have the correct names for the VM, and/or other groups.

To do that use the following command:
Get-ClusterGroup | Select Name, AntiAffinityClassNames

This will give you a result with already set AntiAffinityClassNames, as well as the names you should use to add them to the group. It is possible to have multiple groups on one machine, so you can add multiple roles

$AntiAffinityCollection = New-Object System.Collections.Specialized.StringCollection

Once you have the groups set, you can add the groups to the VM within the cluster.

(Get-ClusterGroup -Name “VM01”).AntiAffinityClassNames = $AntiAffinityCollection
(Get-ClusterGroup -Name “VM02”).AntiAffinityClassNames = $AntiAffinityCollection

Afterwards you can check it using the same command as before.

Get-ClusterGroup | Select Name, AntiAffinityClassNames

This will (in a 3 cluster or bigger environment) automatically move/start the machines on different nodes if it is possible.

It is possible to force to not allow them on the same machine, but that will fail that machine should it require to go to the same hypervisor even if it would be for updates.

To force the VM to not be allowed; you will need to use the following powershell command:
(Get-Cluster).ClusterEnforcedAntiAffinity = 1

If you would want to have it back where it is a “soft” fail use the following powershell command:
(Get-Cluster).ClusterEnforcedAntiAffinity = 0

To read more about (Anti)AffinityClass please look at the microsoft website: Cluster affinity | Microsoft Docs

That’s it for now!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.