VMware {code} Community
ps12
Contributor
Contributor

get all virtual machines path

Hi all

I need to get all my virtual machines path's from my Datacenter.

I've seen that SimplClient samples, returns all the object but not the path of the single object like its father's folder.
Does anyone have samples codes?

I'm using VMWARE SDK 4.1 with C#.

thanks

0 Kudos
2 Replies
paul_xtravirt
Expert
Expert

Hi,

Sorry, I dont have a c# sample - but basically you will need to grab all the VMs from the datacenter level, then process each in turn. Using a property collector, grab the 'parent' property (Its a managedobjectreference to a folder) and then recursively work up until there are no more parents. You will then have the VM inventory path, assuming you join each of the discovered 'parent' entries together. You will need to resolve each of the parent objects are you find them, so writing something to resolve a managedobjectreference to a string would be useful, as you could call it as a function each time, returning a string.

Dont forget to use a seperator when joining each parent as a string, e.g. use a '\' as a seperator

If you found this helpful, please consider awarding some points
0 Kudos
Kjellski
Contributor
Contributor

Actually I think it should be a forward slash: " / "

But maybe I misinterprete the paths that need to be entered when searching with the SearchIndex via Managed Object Browser under "https://vcenter/mob/?moid=SearchIndex" for example.

0 Kudos