Automation

 View Only
  • 1.  Getting Cluster Name of VM

    Posted Nov 13, 2009 06:26 PM

    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!



  • 2.  RE: Getting Cluster Name of VM

    Posted Nov 13, 2009 11:16 PM

    You can use something like this

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



  • 3.  RE: Getting Cluster Name of VM

    Posted Nov 16, 2009 01:07 PM

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



  • 4.  RE: Getting Cluster Name of VM

    Posted Nov 16, 2009 06:37 PM

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



  • 5.  RE: Getting Cluster Name of VM

    Posted Nov 21, 2009 01:45 AM

    Thanks LucD....perfect!