Automation

 View Only
  • 1.  Get list of hosts available to run a VM?

    Posted Jul 13, 2010 05:14 PM

    I've searched the forums but haven't found the answer for this, but please let me know if I missed it. Given a VM name, I would like to output a list of hosts that the VM can run on. The only way that I have been able to do this is a two step process and I'm trying to get it into a one liner:

    Suppose the VM name is SQLVS01

    $a = foreach ($vmname in get-vmhost -vm SQLVS01){get-cluster -vmhost $vmname}

    Check the value of $a for example purposes:

    $a

    Name HAEnabled HAFailover DrsEnabled DrsAutomationLe

    Level vel

    -


    -


    -


    -


    -


    SQLCluster1 True 1 True FullyAutomated

    Use the retrieved cluster name as a parameter:

    C:\> get-vmhost -location $a.name

    Output shows the VMHosts in that cluster

    Name

    -


    VMHost1

    VMHost2

    ..etc..

    Any ideas? This must be simpler than I am making it.

    Thanks,

    Ed



  • 2.  RE: Get list of hosts available to run a VM?
    Best Answer

    Posted Jul 13, 2010 05:37 PM

    How about this?

    get-vm SQLVS01 | get-cluster | get-vmhost | select name

    _____________

    Jason

    Twitter: @jrob24



  • 3.  RE: Get list of hosts available to run a VM?

    Posted Jul 13, 2010 05:41 PM

    Works like a charm! I tried something similar but it gave me an error that pipeline input was not supported by the object, so the syntax that I used must have been off. Thanks!

    Ed Z



  • 4.  RE: Get list of hosts available to run a VM?

    Posted Jul 13, 2010 06:24 PM

    The problem with that solution is that it won't take into account when one of those hosts is for example in maintenance.

    This is a bit more complex but should take hosts that are powered off or in maintenance into acocunt.

    $vmName = <vm-name>
    $vmCompatChecker = Get-View (Get-View ServiceInstance).Content.vmCompatibilityChecker
    $hosts = $vmCompatChecker.CheckCompatibility((Get-Vm -Name $vmName | Get-View).MoRef,$null,$null,"hostTests")
    $hosts | %{(get-view -Id $_.Host).Name}
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 5.  RE: Get list of hosts available to run a VM?

    Posted Jul 13, 2010 07:14 PM

    Could you not also do it this way?

    get-vm SQLVS01 | get-cluster | get-vmhost | where {$_.State -eq "Connected"} | select Name

    _____________

    Jason

    Twitter: @jrob24



  • 6.  RE: Get list of hosts available to run a VM?

    Posted Jul 13, 2010 07:23 PM

    Probably you're right.

    Problem is that I don't know what exactly is in those "hostTests".

    ____________

    Blog: LucD notes

    Twitter: lucd22