Raiders of the lost VM´s in Hyper-V 2012 Cluster nodes

Inspired by Indiana Jones, I have made a little Powershell function to search cluster nodes for VM´s that has not been cluster enabled. If you create a VM in the Hyper-V manager or the Hyper-V powershell cmdlets, the VM is not highly available by default, even if you added it to a SMB share.

What do I do then, I only use one parameter and that is the cluster name, from this I get the HA – enabled VM´s and then check them for all VM´s registered on the hosts. After this I do a comparison and get a list of the VM´s objects that are not Cluster enabled, this can be pipelined to Add-VMToCluster cmdlet (an alias for Add-ClusterVirtualMachineRole) and you are home safe :-). Of course there might be situations where you want a VM to reside only on one cluster node and not be highly available, Guest Clustering is one case where this might be a reason to not add them to a cluster. And if the VM has the configuration and storage locally you wont be able to add it to the cluster anyway

I can easily with PowerShell get the VM´s that are already HA enabled, but with this command I do not get the other VM´s on the cluster nodes.

1Get-VM -ClusterObject (Get-ClusterResource -Cluster hypcl30 | where ResourceType -eq "Virtual Machine")

So if I want to get only the VM´s not cluster enabled, here is the function

01<#
02.Synopsis
03   This function search the hosts for VMs tha are not HA enabled
04.DESCRIPTION
05   This function lets you find what VM´s that is running on your hosts and not activated on the virtual machine role on the cluster
06.EXAMPLE
07   Get-VMNotInCluster -Cluster HVCL30
08.Link
09vniklas.djungeln.se
10 
11.Notes
12    Author: Niklas Akerlund /20121004
13#>
14function Get-VMNotInCluster
15{
16    [CmdletBinding()]
17    [OutputType([int])]
18    Param
19    (
20        # Name of the Cluster
21        [Parameter(Mandatory=$true,
22                   ValueFromPipelineByPropertyName=$true,
23                   Position=0)]
24        $Cluster
25    )
26    Process
27    {
28        $ClusterNodes = Get-ClusterNode -Cluster $Cluster
29        $VMsInCluster = Get-VM -ClusterObject (Get-ClusterResource -Cluster $Cluster | where ResourceType -eq "Virtual Machine")
30        $VMsTotal = Get-VM -ComputerName (Get-ClusterNode -Cluster $Cluster).Name
31        $VMsNotInCluster =@()
32        
33        foreach ($VM in $VMsTotal){
34                if($VMsInCluster -notcontains $VM){
35                    $VMsNotInCluster += $VM
36                }
37        }
38        $VMsNotInCluster
39    }
40}

And here is a screendump of it running

 

And here is when I enable so that all VM´s are Highly Available

Now I do not have so many VM´s in my test environment but in a production environment maybe you can see the potential of knowing that all VM´s on all Clustered nodes are made HA enabled.

Comments

Tolli
Reply

Thanks for this post. It helped so much

Leave a comment

name*

email* (not published)

website