VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Accessing the cluster name of a VM

Is it possible to create a property that accesses the cluster name that a VM is on, such as this:

get-vm | select name,

@{n="cluster";e={ GetTheClusterNameSomehow}}

?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Something like this should do the trick.

$vm = Get-VM -Name MyVM
$vm | Select Name,@{n="Cluster";E={
 
$rp = Get-View $_.ExtensionData.ResourcePool
 
$parent = Get-View $rp.Parent
 
While ($parent -isnot [VMware.Vim.ClusterComputeResource]){
   
$parent = Get-View $parent.Parent
  }
 
$parent.Name
}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Something like this should do the trick.

$vm = Get-VM -Name MyVM
$vm | Select Name,@{n="Cluster";E={
 
$rp = Get-View $_.ExtensionData.ResourcePool
 
$parent = Get-View $rp.Parent
 
While ($parent -isnot [VMware.Vim.ClusterComputeResource]){
   
$parent = Get-View $parent.Parent
  }
 
$parent.Name
}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK thanks

0 Kudos