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 is “Inside Microsoft Teams”?
“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.
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.