Virtualization Pro Tips Blog

Need to Separate Hyper-V VMs? Use AntiAffinityClassName.

As the size of your virtual environment scales, you’ll quickly find yourself needing to segregate virtual machines from each other. Perhaps you have a pair of domain controllers that should never exist on the same Hyper-V host. Maybe you’ve got a two-node cluster that should always be separated. Keeping virtual machines separated in Hyper-V is a task that doesn’t seem to have an immediate solution. There’s simply no exposure for setting “anti-affinity” rules in the Hyper-V Manager console or System Center Virtual Machine Manager.

What you may not know is that Windows Failover Clustering’s mechanism for keeping VMs separated is exposed as a property within the cluster.exe command line tool. This property was first introduced in Windows Server 2003, so it’s been around for a while. It’s also not necessarily designed with Hyper-V in mind. You can use AntiAffinityClassName to keep any cluster resources segregated. But this dusty old property has been getting a lot more attention these days with people’s need to split VMs across hosts.

The problem is, figuring out Here’s how to use it. Let’s assume for a minute that you have two servers named Server1 and Server2 that should never reside on the same host, no matter what happens with node failures or other resource rebalancing. To ensure their segregation, create a label called “Anti” and associate that label with the cluster groups for each virtual machine:

  • cluster group “Server1” /prop AntiAffinityClassNames=”Anti”
  • cluster group “Server2” /prop AntiAffinityClassNames=”Anti”

You can later view which AntiAffinityClassName you’ve assigned a virtual machine by looking at its cluster group properties:

  • cluster group “Server1” /prop

Be aware that setting AntiAffinityClassName will not completely prevent two cluster groups from failing over to the same node. If there is no other alternative, such as in the case of a multi-node failure, the groups will be forced to collocate. In every other situation, however, AntiAffinityClassName will keep those groups separate, as long as options exist for it to do so.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.