VMware Cloud Community
crigano
Contributor
Contributor

Getting Cluster Name of VM

Hello,

I've got a simple inventory query setup that pulls back all of the virtual machines in vCenter. Is there any easy way to get the cluster name that the VM resides in? I'm not finding a basic VM property that contains this information. I see there's a "parent" property, so I'm not sure if that's what I need to use or not. A code snippet below is basically what I'd like to do:

IList vmList = client.FindEntityViews(typeof(VirtualMachine), null, null, null);

foreach (VirtualMachine vm in vmList)

{

Console.WriteLine(vm.Name);

Console.WirteLine(vm.??)

}

Any help is greatly appreciated. Thanks!

Tags (3)
Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

You can use something like this

Get-VM | select @{N="VMname"; E={$_.Name}}, @{N="ClusterName"; E={($_ | Get-Cluster).Name}}


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

Reply
0 Kudos
crigano
Contributor
Contributor

Thanks, but this is PowerShell code. I need a solution in C# using the .NET SDK.

Reply
0 Kudos
LucD
Leadership
Leadership

No problem, perhaps you better submit your question in one of the Developer forums.


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

Reply
0 Kudos
VirtualMonster3
Contributor
Contributor

Thanks LucD....perfect!

Reply
0 Kudos