Hello All,
Iam developing an application in C# in which I have to delete a virtual machine from ESX server.
Is there a direct way to delete a VM using its inventory path , or should I first get the path of its vmx file and then use the API "DeleteFile".
If I have to use the "DeleteFile", the first Argument it takes is a managedobjectreference ot the HostDatastoreBrower used to make the call.
Where can I get this reference?
Thanks a lot.
I have use the following to get the name of the file
VM.config.files
And I used the following to get the Hostdatastorebrowser
VM.environmentBrowser.hostdatastorebrowser
but after executing the API "DeleteFile" only the .vmx file was deleted and the virtual machine still can be seen in the Inventory.
How can I delete a Virtual Machine?
...
Message was edited by:
virtualdud3
Thanks All,
I have solved it.
You can delete a Virtual Machine in c# by using the following API.
service.DestroyTask(ManagedObjectReference VM);
Where VM is a reference to the Virtual Machine you want to delete you can get this reference by the following.
string PathToVm="\[Datacenter]/vm/\[VM Name]";
VM=_service.FindByInventoryPath(_sic.searchIndex, PathToVm);
Best Wishes.