I have a VM view, and i'd like to see what cluster it belongs to.
I've poked around the object with no luck. I saw some stuff about filtering based on a cluster (SearchBase) but since i've already queries for the VMs i'd prefer not to have to go ask the server.
Is it stored in the VM View anywhere? The parent doesnt look safe, since it could be a folder.
Thanks
Justin
Have a look at Get-View -ViewType virtualmachine, is it possible to get the cluster info of the VM ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hmm that looks expensive, I'll be calling it for 10,000+ vms, some of which are 4 folders deep in the cluster, I suspect this will be slow and painful.
I think when i get the VM view i'll do it by cluster
So pull the ClusterComputeResource and then use it as the search root for the VirtualMachine query.
That could be correct, try like this then
foreach($cluster in Get-View -ViewType ClusterComputeResource -Property Name,Host){
foreach($esx in Get-View -Id $cluster.Host -Property Name,VM){
if($esx.VM){
Get-View -Id $esx.VM -Property Name |
Select @{N='Cluster';E={$cluster.Name}},Name
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I actually did it more like this
$clusters = get-view -viewtype clustercomputeresource
foreach($cluster in $clusters)
{
$cluster | add-member -membertype noteproperty -name vms -value $null
$cluster.Vms = get-view -viewtype virtualmachine -scope $cluster.name
}
im pulling this from memory, so it might not be 100%, but rather than call the view a few time (host/vm) im using the scope to get the vms from the cluster.
This is working out well for me
thanks!