Spotlight on the New DRS Groups and VM-Host Rule Cmdlets!

We’re kicking off the first in a series of blog posts taking an in-depth look at some of the new cmdlets that were made available with the PowerCLI 6.5.1 release. This first post is going to be covering the cmdlets targeted at managing DRS groups and their associated rules.

These new cmdlets are as follows:

  • Get-DrsClusterGroup
  • New-DrsClusterGroup
  • Set-DrsClusterGroup
  • Remove-DrsClusterGroup
  • Get-DrsVMHostRule
  • New-DrsVMHostRule
  • Set-DrsVMHostRule
  • Remove-DrsVMHostRule

If you’ve never used DRS groups and DRS affinity rules or don’t know what they are, these are a way to control which VMs are able to exist on which hosts. This control is leveraged through either affinity or anti-affinity rules that are configured at the cluster level. These rules are configured between groupings of VMs and groupings of hosts. These rules also have types, which basically describes how the enforcement should work. The types are: Must Run On, Should Run On, Must Not Run On, Should Not Run On

Please see the documentation for more information about: DRS Affinity Rules

Taking A Closer Look – A Use Case Demonstration

We have been given a lab environment and our end result is to have the even numbered App VMs run on the even numbered hosts whenever possible, and likewise with the odd numbered VMs and hosts.

First, a look at the lab environment:

  • 1 Cluster
  • 4 Hosts
  • 50 VMs

Environment Setup

We’ll start by taking a look at the DRS Cluster Group cmdlets. These are used in order to create, manage, and remove VM and host based DRS groups. These cluster groups are then referenced by the DRS VM-Host affinity rules, which we’ll discuss in a bit.

Let’s create the first host DRS group, which will be for the odd numbered hosts. This can be done with the ‘New-DrsClusterGroup’ cmdlet while specifying a name, the cluster, and the desired hosts. A command for our sample environment looks like this:

Creating a DRS group

We’ll repeat a similar process for the even hosts, only this time we’ll store the cluster and desired hosts in their own variables:
Creating a DRS group

We now have the required host DRS groups, so we can move forward and create the VM DRS groups. These are created with the same ‘New-DrsClusterGroup’ cmdlet, except we’ll now use the VM parameter and specify the VMs for each group.

Starting again with our odd numbered VMs, we’ll use the following command:

Creating a DRS group

If you’ll notice, that’s nowhere close to all of the necessary odd numbered VMs. We’ll now make use of the ‘Set-DrsClusterGroup’ cmdlet to add the remaining VMs (which I’ve already stored into a variable). This cmdlet also requires usage of either the ‘Add’ or ‘Remove’ parameter in order to specify what kind of modification is being requested.

The command to add the remaining odd system should be similar to the following:

Updating a DRS group

We’ll repeat a similar process for the even VMs’ DRS group:
Creating a DRS group

Before moving on to creating the VM-Host affinity rules, let’s review the DRS groups we’ve created to this point with the ‘Get-DrsClusterGroup’ cmdlet.
Displaying the DRS Groups

This cmdlet also has a couple parameters to help gain additional information. The ‘Type’ parameter can be used to specify whether to return VM groups or host groups. The ‘VM’ and ‘VMHost’ parameters can be used to only return DRS groups belonging to that VM or host.

Some examples of these parameters in use:
Filtering the list of DRS groups

Moving on to the creation of the rules… We’ll be using the ‘New-DrsVMHostRule’ cmdlet along with several parameters. These parameters will be ‘Name’, ‘Cluster’, ‘VMGroup’, ‘VMHostGroup’, and ‘Type’. Most of those should be self-explanatory, but ‘Type’ may not be. Thanks to tab complete, we’ll see that the type options are ‘MustRunOn’, ‘ShouldRunOn’, ‘MustNotRunOn’, and ‘ShouldNotRunOn’ and apply to how the rule is enforced against the cluster.

Remembering that our goal is to have the even VMs run on the even hosts whenever possible, we’ll issue the following command:

Creating a VM-Host Rule

We’ll do a similar command for the odd rule:
Creating a VM-Host Rule

Our objective should be complete and we can verify that by using the ‘Get-DrsVMHostRule’ cmdlet. The output should be similar to the following:
Displaying VM-Host Rules

These VM-Host rules can also be modified once they’ve created with the ‘Set-DrsVMHostRule’ cmdlet. This cmdlet has the ability to rename the rule, enable or disable it, and modify either the VMGroup and/or the VMHostGroup.

The rules can easily be disabled using the following command:

Modifying VM Host Rules

This environment happens to be a lab, so before wrapping up this post we should probably clean it up. We can do this while utilizing the ‘Remove-DrsClusterGroup’ and ‘Remove-DrsVMHostRule’ cmdlets. The commands could look like the following:

Cleaning up the lab environment


These eight new cmdlets are a terrific addition to the PowerCLI 6.5.1 release. They are also a great compliment to the already existing DRS cmdlets! Start using them today and let us know your feedback!


17 comments have been added so far

  1. Great article. The way you explained each and everything about the new DRS Groups and VM-Host Rule Cmdlets is really very good . very well explained. Thanks for sharing with us now my all the doubts has been cleared.

  2. Excellent demo and explanation. Thank you very much.

    Is this a ‘better’ replacement for the New-DrsRule cmdlet(s)? What are the differences?

    1. No, no updates to the existing DrsRule cmdlets. Those target the management of VM-VM affinity rules, while these new rules target VM-Host affinity rules.

      If there’s anything, functionality-wise, that you would like to see added to these cmdlets, we recently stood up the public PowerCLI feature request site. You could add your ideas there:

  3. Sorry, but cmdlet as Get-DrsClusterGroup not work.

    I downloaded powercli 6.5.1 from myvmware website.

    I receive this error when run this cmdlet :

    Get-DrsClusterGroup : The term ‘Get-DrsClusterGroup’ is not recognized as the
    name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    At line:1 char:1
    + Get-DrsClusterGroup -Cluster $cluster
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-DrsClusterGroup:String) [],
    + FullyQualifiedErrorId : CommandNotFoundException

    How can resolve it ?

    Thanks for all.

      1. Did you happen to uninstall any prior versions of PowerCLI which were installed by MSI?

        Another option, what’s the output if you run the following command:
        Get-Module -Name VMware.VimAutomation.Core -ListAvailable

  4. how would I enable predictive DRS on a cluster from powercli, assume that it is enabled in VROPS and DRS is enabled already on the cluster (but not predictive)

  5. Hi,

    What if we have multiple clusters with different names of DRS groups ? how to incorporate cluster name within the add or remove command ??

  6. If the last VM of a group was deleted
    I can’t use Set-DrsClusterGroup anymore. It don’t let me add a VM this group.

Leave a Reply

Your email address will not be published.