locked
Get list of VM's not in Failover Cluster RRS feed

  • Question

  • We use a self made tool to create Hyper-V VM's, which also makes them part of the Failover Cluster.
    Except sometimes when it doesn't.

    Therefore I am creating a script that will check the nodes for VM's not added, and add them using Add-ClusterVirtualMachineRole.

    The problem I am facing is creating the list, and it may be easier and faster then I have in mind.
    What I can think of is making a list of all VM's on all nodes, and a list of VM's in the Failover Cluster (ClusterResource where ResourceType is "Virtual Machine") and diff that to use in a foreach loop.
    But that takes a lot of time with nodes, across numerous clusters, having between 50 and 70 VM's each.

    What might be an easier and faster way of doing this?
    Maybe I am simply unbeknownst of certain cmdlets or features of cmdlets though.

    Friday, September 14, 2018 2:25 PM

All replies

  • Hi, 

    Thanks for your question.

    We can use this powerCLI command to list all VMs in a cluster.

    Get-Cluster "Cluster Name" | Get-VM
    

    Details: PowerCLI command to list all VMs in a cluster

    We can use powershell command "Get-VM" to get the VMs on one or more Hyper-V hosts in the environment.  

    Get-VM
       [[-Name] <String[]>]
       [-CimSession <CimSession[]>]
       [-ComputerName <String[]>]
       [-Credential <PSCredential[]>]
       [<CommonParameters>]

    Furthermore, here's a discussion regarding powershell scripts how to get the VMs in one or more cluster, it may be helpful.

    PowerShell: How to return all the VMs in a Hyper-V Cluster

    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

    Hope above information can help you. If you have any question or concern, please feel free to let me know.

    Best regards,

    Michael


    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, September 17, 2018 6:37 AM
  • Hi,

    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,

    Michael


    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, September 19, 2018 5:45 AM
  • Sorry about the late reply. I saw the e-mail notification, and just forgot to check it.
    Was busy yesterday.

    Your first command doesn't work for me.
    It returns the following error that I need to look up.

    Get-VM : The parameter is not valid. A cluster object was passed that is not valid. Run the command again and specify an object that represents a cluster group or cluster resource.

    I noticed a -ClusterObject parameter for Get-VM but that will only show a list of VM's that are part of the cluster.
    I want a list of VM's, on Hyper-V nodes, that are not part of the cluster.

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

    The above command (from the link you mentioned) shows all VM's in the cluster.
    It's a nice one-liner, but I need the opposite :-)


    Wednesday, September 19, 2018 9:21 AM