title: How to get Virtual Machine name using VMWare API?
body: <p>I'm using the Vestris.VMWareLib API to remotely control my VMs on an ESX 5.0 server. I use the VMWareVirtualMachine.Open method to power on my virtual images. My code is written in C#. The problem is that you need to know the path to the datastore before you can power on the image - I'd like to be able to power it on knowing the VM name only. Is there a way to do this? I've included my current code below.
  Thanks, John</p>
  
  <pre><code>using Vestris.VMWareLib;
  
  //Works if VM name is in the path but what if it isn't?
  List&lt;VMWareVirtualMachine&gt; vitualMachines = esxServer.RegisteredVirtualMachines.ToList();
  VMWareVirtualMachine virtualMachine = vitualMachines.Where(vm =&gt; vm.PathName.Contains(vmName)).First();
  VMWareVirtualMachine virtualMachine = esxServer.Open(vmName);
  </code></pre>
  
  <p>There's a method called VMWareVirtualMachine.GetProperty() which can be used to obtain the VM name but I don't know how to use it. Any suggestions or ideas how I can do this?</p>
  
  <p>Thanks,
  John</p>