VMware {code} Community
aceishigh
Contributor
Contributor
Jump to solution

How to get VM path to .vmx file when you have the VM name?

Hi All,

I'm using the latest release of VIX API to power on VMs on an ESX server. I'm working with C# in Visual Studio 2012 and currently, I power on the VM using the following code:

VMWareVirtualMachine virtualClientMachine = host.Open(vmMachinePath, 2100);

While this works, I think it's better to instead be able to power on the VM when you know the VM name and not the path. So, how can I get the VM path to the vmx file when I know the name of the VM? For example, if my VM on the ESX server is called WIN7GERMAN, how do I then get the path and pass this to the host.Open function?

Thanks for any help or code.

John

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
lemke
VMware Employee
VMware Employee
Jump to solution

VM names are not unique, which is why this isn't supported.

You can use VixHost_FindItems() and search for the undocumented VIX_PROPERTY_FOUND_ITEM_NAME property and use the associated VIX_PROPERTY_FOUND_ITEM_LOCATION to get the value to pass to VixHost_OpenVM().  You'll have to deal with any duplicate names however Smiley Happy

View solution in original post

Reply
0 Kudos
2 Replies
lemke
VMware Employee
VMware Employee
Jump to solution

VM names are not unique, which is why this isn't supported.

You can use VixHost_FindItems() and search for the undocumented VIX_PROPERTY_FOUND_ITEM_NAME property and use the associated VIX_PROPERTY_FOUND_ITEM_LOCATION to get the value to pass to VixHost_OpenVM().  You'll have to deal with any duplicate names however Smiley Happy

Reply
0 Kudos
aceishigh
Contributor
Contributor
Jump to solution

That's a pity. It's not ideal to pass paths each time I want to power on a VM but if that's the best way, then so be it.

Thanks for the helpful explanation.

John

Reply
0 Kudos