How to use VM Groups in HYPER-V

Vm management is getting complicated if you have hundreds of Virtual Machines.

VM Groups in HYPER-V is an another way to manage Virtual Machines by grouping because you need to perform an orchestrated action and get your life easier.

The most common way to use VM Groups is if you want to run a Hyper-v Replication against a pair of Virtual Machines.

But when start to use VM Groups i realize that you can use it in different situations like:

  • In Remote Desktop Farm: You have multiple Remote Desktop Servers and sometimes requested to perform an orchestrated action in all Remote Desktop Servers
  • In Domain Controllers: If you have more than 2 it will help you in some scenarios to manage it as VM Group.
  • Virtual Machines that yo want to have it as Group base on your infrastructure

These are some of the scenarios but base on your environment i am sure that you will find how can group some of the Virtual Machines for better management.

So let's start to explain how can create and manage the VM Groups.

If you want to use the VM Group you must do it from Powershell because you will not find any GUI option in HYPER-V Manager.

You can use the VM Groups with the following Powershell cmdlets 

  •  Add-VMGroupMember
  •  Get-VMGroup
  •  New-VMGroup
  •  Remove-VMGroup
  •  Remove-VMGroupMember
  •  Rename-VMGroup

Let's do some examples in practise for better understanding

> Video : Implementing Windows Server 2016 Hyper-V by Greg Shields (MVP)

 

How to create VM Groups in HYPER-V

  • In my Lab i have create 4 FileServers that sometimes must perform an orchestrated action
  • Open Powershell as Administrator
  • Type the following command to create the VM Group

 New-VMGroup fileservers -GroupType VMCollectionType

 

  • Now lets add the Virtual Machines that we want in the Group fileservers
  • We can add in variables the virtual machine names as in the following code 

$flsrv1=get-vm -Name "flsrv01"
$flsrv2=get-vm -Name "flsrv02"
$flsrv3=get-vm -Name "flsrv03"
$flsrv4=get-vm -Name "flsrv04"
Add-VMGroupMember -Name fileservers -VM $flsrv1, $flsrv2,$flsrv3,$flsrv4 

 

  • or you can use it as follow to add members.

 

add-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv01")
add-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv02")
add-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv03")
add-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv04")

  • If you want to verify that the members added in the Group type the following command.
  • You can see the VM Members.

Get-VMGroup

 

 

  • We create the VM Group and added all the Fileservers as members.
  • Let's try to start the Virtual Machines all together.
  • Type

Start-VM -VM(Get-VMGroup fileservers).VMMembers

 

  • Or you can shutdown the viirtual machines

Stop-VM -VM(Get-VMGroup fileservers).VMMembers

 

This is a simple example that can give to understand how can use it the VM Groups.

Now let's think yourself how can use VM Groups to help you manage better your Virtual Machines

How to delete VM Group in HYPER-V

If you would like to delete the VM Group you must remember that the VM Group must be empty unless you will get an error

Let's do an example

  • Open Powershell as Administrator
  • Let's try to delete the VM Group without remove the members
  • As you can see you get an error

 

  • You can type the following command to remove the memeberships from the Group

$flsrv1=get-vm -Name "flsrv01"
$flsrv2=get-vm -Name "flsrv02"
$flsrv3=get-vm -Name "flsrv03"
$flsrv4=get-vm -Name "flsrv04"
Remove-VMGroupMember -Name fileservers -VM $flsrv1, $flsrv2,$flsrv3,$flsrv4 

  • or with another way

remove-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv01")
remove-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv02")
remove-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv03")
remove-VMGroupMember -Name fileservers -VM (get-vm -Name "flsrv04")

 

  • Now you can delete the VM Group 

Remove-VMGroup -Name fileserver

 

As you can see it's very easy to use VM Groups with Powershell if you have lot of Virtual Machines.

You don't need to be an expert in Powershell and it's sure that can help you a lot in VM Management.

You can send me an email at info@askme4tech.com  or do your comments in Twitter or Facebook

I invite you to follow me on Twitter or Facebook. If you have any questions, send email to me at info@askme4tech.com.