Automation

 View Only
  • 1.  ClusterName of a VM

    Posted Feb 13, 2013 09:29 AM

    Hi,

    Is there any way to retrieve the cluster name from the view object of VM and esx host. For example

    $vm = get-vm -Name VMname

    $vmview =  $vm | get-view

    Now I want to retrieve the cluster name of the VM using $vmview. Same for host as well.

    Please help.



  • 2.  RE: ClusterName of a VM

    Posted Feb 13, 2013 09:34 AM

    This should return the clustername

    Get-Cluster -VM $vm | Select -ExpandProperty Name


  • 3.  RE: ClusterName of a VM

    Posted Feb 13, 2013 09:40 AM

    Hi LucD,

    Thanks for your reply.

    Yes I already know the way you have shown below. But I want to retrieve it using the view properties of the vm/esx object for some reason. Is it possible?



  • 4.  RE: ClusterName of a VM

    Posted Feb 13, 2013 09:46 AM

    Sure, everything is possible with PowerShell/PowerCLI.

    Something like this should do the trick

    $vm = Get-VM MyVM 
    $rp
    = Get-View $vm.ExtensionData.ResourcePool
    while
    ($rp.GetType().Name -ne "ClusterComputeResource"){   $rp = Get-View $rp.Parent
    }
    $rp.Name


  • 5.  RE: ClusterName of a VM
    Best Answer

    Posted Feb 13, 2013 09:57 AM

    You can get the clustername from a vmview or hostview object with:

    $ClusterName = (Get-View (Get-View $VmView.Runtime.Host).Parent).Name
    $ClusterName = (Get-View $VMHostView.Parent).Name
    
    



  • 6.  RE: ClusterName of a VM

    Posted Jan 18, 2021 10:37 AM

    Perfect, thanks LucD.