Detecting and Grouping Ungrouped VMs

One of my customers uses DRS groups heavily.  The environment contains a set of specialized ESXi servers for a specific subset of machines and a set of general ESXi servers for everything else.  However, in order to maximize availability, all of these ESXi servers are part of one big cluster.  That means that every VM in their environment must be a member of at least one DRS group, placing the VM on either these specialized ESXi servers or the general ESXi servers.  Until we get an automated solution in place (probably through Orchestrator), we need to depend on the administrators to place the VM in the correct group (almost always the general group) upon machine creation.  As you might expect, that's not going too well.

So, I put together a quick PowerCLI script to detect any VMs that are not grouped and (optionally) place them into the specified group.  This is what I came up with!

The script is easy to use, but it requires a non-standard PowerCLI module.  To get it working, you'll need to download and install the DRSRule PowerCLI module.  That module was put together by a few of the heavyweights in the PowerCLI community and introduces a whole set of cmdlets that are built to manage DRS cluster rules (which is an area that the standard PowerCLI installation is a little lax on).

After you've installed DRSRule, the script can be run in one of two modes (as determined by the parameters that you use): either -Report or -PlaceVMs.  If you give it the -Report switch, it will generate a report of all VMs in the specified cluster that are not members of any DRS Rule Group.  If you give it the -PlaceVMs switch, that will place the VMs into the specified group... and open up a few other options.

When using -PlaceVMs, the script requires that you also give it the -GroupName parameter.  This parameter is just the name of the (pre-existing) DRS Group to which you want to add any ungrouped VMs.  There's also an optional parameter, -VMName.  This should be a regular expression that matches only the VMs that you want to manipulate.  For example, if you have a Domain Controllers group and you know that every DC name in your environment ends like ...dc#, you could give it the "dc\d$" regular expression for the -VMNames parameter.  The -VMNames parameter is optional; if you do not specify it, it will place all ungrouped VMs within the cluster.  All of these operations are contained by the cluster; that is because the DRS VM Group object is actually defined in the cluster itself.

As always, this script is posted as-is with no implied guarantee.  While it worked for me in my situation, that doesn't mean that it will work for you in yours.  Test thoroughly and, if you fix something, let me know so that I can update the script (or fork it and update it yourself)!


Comments

Popular posts from this blog

PowerShell Sorting by Multiple Columns

Clone a Standard vSwitch from one ESXi Host to Another

Deleting Orphaned (AKA Zombie) VMDK Files