Hyper-V Virtual Machine Groups
In this post, I will show you how you can use virtual machine groups on Windows Server 2016 Hyper-V to manage a set of virtual machines. This includes adding support for operational actions on VHDX Sets, such as Hyper-V Replica.
What Are Virtual Machine Groups
Let’s say that you had a set of one or more virtual machines that you wanted to perform some repeatable tasks against. Maybe you need to perform an orchestrated action. An example of this would be enabling Hyper-V Replica against a pair of virtual machines that share some VHDX Sets, such as shared VHDX v2.0. We can use virtual machine groups to perform these actions.
Creating a Virtual Machine Group
All virtual machine group actions are performed using PowerShell. There is no GUI option in Hyper-V Manager. The relevant cmdlets identify virtual machines only by the object and not by the name. In larger deployments such as a private cloud, virtual machine names can be reused by different tenants or customers.
Make note, failover clustering has a different kind of group for ordering the failover of virtual machines.
We can create a new virtual machine group using the New-VMGroup cmdlet. The -type flag is instructing Hyper-V to create a virtual machine group. We also have another type called a management group, which we will look at later.
New-VMGroup -Name "CrmDBClu" -GroupType VMCollectionType
I can add a single virtual machine to this new group. This is shown below. I am using the name of the virtual machine to return the virtual machine object, which is what we added to the group.
Add-VMGroupMember -Name "CrmDBClu" -VM (Get-VM "VM1")
Alternatively, I can add a pair of virtual machines.
Add-VMGroupMember -Name "CrmDBClu" -VM (Get-VM "VM1"),(Get-VM "VM2")
We can query what virtual machines are in a group.
(Get-VMGroup -Name "CrmDBClu").VMMembers
We can also query what the group memberships are for the virtual machines.
Get-VM | FT Name, Groups
We can use this group to perform orchestrated actions. The following is an example of enabling Hyper-V Replica for virtual machines that use shared VHDX files. Notice that we substituted the name of the virtual machine being replicated with the list of members from the virtual machine group.
Enable-VMReplication -VM (Get-VMGroup CrmDBClu).VMMembers -ReplicaServerName DRHost -ReplicaServerPort 80 -AuthenticationType Kerberos -CompressionEnabled 1 -ReplicationFrequencySec 30 -AutoResynchronizeEnabled 1
The above is how you can replicate virtual machines using VHDX Sets in a supported manner.
Virtual Machine Management Groups
It is possible to create a group of groups. Think about having a 3-tier application:
- Web servers in a virtual machine group
- Application servers in a second virtual machine group
- Database servers in a third virtual machine group
You can add all three virtual machine groups into a single management group. First, we create a management group.
New-VMGroup -Name "MgmtGroup" -GroupType ManagementCollectionType
Then, we can add existing virtual machine groups into this management group.
Add-VMGroupMember -VMgroup (Get-VMGroup "MgmtGroup") -VMGroupMember (Get-VMGroup "CrmDBClu")
Right now, virtual machine groups are only something that we might use with Hyper-V Replica or to replace an array in a script. Virtual machine groups live on after a script ends. I have the feeling that we are just seeing the glimpse of what virtual machine groups might offer in the future.
More in Windows Server 2016
Microsoft Acknowledges New Netlogon Issues On Windows Server Machines
Feb 25, 2022 | Rabia Noureen
How to Fully Patch the PrintNightmare Vulnerability
Jul 9, 2021 | Brad Sams
Everything You Need to Know About Windows - February 2020
Mar 2, 2020 | Russell Smith
Migration Tools for the Azure Hybrid Cloud
Feb 13, 2019 | Michael Otey
What Does IBM’s Acquisition of Red Hat mean for the Hybrid Cloud?
Nov 13, 2018 | Michael Otey
Understanding Windows Server 2016’s Disaster Recovery Features
Aug 29, 2018 | Michael Otey
Most popular on petri