One of the explanations why I even have continually likeable exploitation PowerShell as a tool for managing Hyper-V is that PowerShell permits you to perform management actions in bulk. Sometimes, though, the property of the task will build standard PowerShell management techniques impractical. Imagine for a flash that you simply wish to perform some management perform on a hundred and fifty virtual machines, however wish to depart all of the organization’s different VMs untouched. simply to create things attention-grabbing, let’s conjointly faux that every one of those virtual machines have immensely completely different names from each other, therefore filtering VMs by name isn’t AN choice.

There are a couple of other ways that you simply may accomplish this kind of task in PowerShell. One in all the lot of common techniques is to make a document or a CSV file containing the names of the VMs that you simply wish to manage. You may then write a script that performs the management activity on each VM that’s listed within the file.

While this can be actually a viable approach, it should generally be a lot of convenient to make virtual machine teams instead. Hyper-V has had the power to cluster virtual machines along for many years currently. Even so, the feature typically goes unused; presumptively as a result of it’s not exposed through the Hyper-V Manager.

Groups’ are helpful for making collections of VMs that have similar management desires. For example, you would possibly cluster all of your domain controllers along.

Creating virtual machine teams

Creating a bunch of virtual machines may be an easy method. All you have got to try to is assign the A name, then tell Windows that the cluster represents a set of virtual machines.

For the sake of demonstration, I even have created 5 virtual machines named VM1 through VM5. These virtual machines don’t really do something special, however let’s faux that all of them have one thing in common with each other which i would like to be ready to jointly manage them. To do so, I’m getting to produce a bunch named MyVMs, and then I’ll add the 5 virtual machines to the cluster.

As antecedently noted, making a virtual machine merely needs you to supply a reputation (in this case it’ll be MyVMs) and to designate the cluster sort as a set of Hyper-V virtual machines. Here is what the command appearance like:

New-VMGroup -Name MyVMs -GroupType VMCollectionType

You can see what the cluster creation method appears like within the screenshot below.

The next step within the method is to feature virtual machines to the cluster. The cmdlet that’s used for this purpose is Add-VMGroupMember. As you’d most likely expect, this cmdlet needs you to supply the name of the virtual machine cluster and also the name of the VM that you simply wish to feature to the cluster. However, there’s one caveat that you simply got to bear in mind of.

When you add a virtual machine to a bunch, you have got to feature it as a virtual machine object. This suggests {that you that you simply that you simply} can’t just provide the name of the VM. Personally, i believe that the best thanks to take care of this demand are to use the Get-VM cmdlet. Here is however i would add the virtual machine named VM1 to the group:

Add-VMGroupMember -Name MyVMs -VM (Get-VM VM1)

I have conjointly seen individuals map the VM name to a variable then add it to the cluster. Here is AN example of what that technique appearance like:

$VM = Get-VM VM2
Add-VMGroupMember -Name MyVMs -VM $VM

Regardless of that technique you employ, it tends to be inefficient to feature virtual machines separately. Fortuitously, you’ll be able to provide the Add-VMGroupMember cmdlet with multiple virtual machine names. Here is however it works:

Add-VMGroupMember -Name MyVMs -VM (Get-VM
VM3),(Get-VM VM4),(Get-VM 

You can see all 3 techniques incontestable within the screenshot below.

As you examine the screenshot on top of, you’ll notice that Windows doesn’t offer any confirmation that you simply have with success more the VMs to a bunch. It’s thus useful to be ready to validate the group’s membership. You’ll be able to do that by exploitation the Get-Group cmdlet.

If you just sort the Get-Group cmdlet followed by the name of the cluster, you’ll see AN abbreviated version of the group’s membership. If you would like to visualize the complete membership list, you’ll got to use a command like this one:

Get-VMGroup MyVMs | Select-Object -ExpandProperty VMMembers

You can see what each of those commands neutralizes the screenshot below.

Bulk management actions:

The one issue that I infrequently hear anyone point out with relevance virtual machine teams is a way to perform bulk management actions against the cluster members. like nearly something in PowerShell, there are multiple ways in which of obtaining the work done. i prefer to map the cluster membership to a variable then reference the variable. Here is AN example of however you would possibly map the group’s membership to a variable:

$VMs = (Get-VMGroup MyVMs).VMMembers

You can verify the variable’s contents by getting into the variable name into PowerShell.

Now that I even have created a variable, I will reference the variable from any virtual machine connected cmdlet. If for instance, I needed to start out all of the VMs in my virtual machine cluster, I may merely type:

Start-VM $VMs

Virtual machine groups: the advantages are obvious:

Virtual machine teams will build it easier to bulk manage your Hyper-V virtual machines. However, these teams aren’t exposed through the Hyper-V Manager, in order that they tend to be the foremost helpful to people who use PowerShell to manage their Hyper-V environments. though similar practicality may be achieved by employing a file containing virtual machine names, exploitation virtual machine teams keeps you from having to script a iteration perform.

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here :