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:
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
How about this?
get-vm SQLVS01 | get-cluster | get-vmhost | select name
_____________
Jason
Twitter: @jrob24
How about this?
get-vm SQLVS01 | get-cluster | get-vmhost | select name
_____________
Jason
Twitter: @jrob24
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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could you not also do it this way?
get-vm SQLVS01 | get-cluster | get-vmhost | where {$_.State -eq "Connected"} | select Name
_____________
Jason
Twitter: @jrob24
Probably you're right.
Problem is that I don't know what exactly is in those "hostTests".
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference