VMware

This Question is Answered

2 "helpful" answers available (6 pts)
1 2 Previous Next 18 Replies Last post: Jul 15, 2009 5:54 AM by Vrunner  

Commandline for removing VMs from "Inventory" posted: Jun 26, 2008 10:01 PM

Click to view lamw's profile Champion 2,803 posts since
Nov 27, 2007

I hope this is possible, but I haven't found a method of removing a Virtual Machine from inventory via the commandline. The reason I'm interested in this command is that I can unregister a VM from the commandline using

vmware-cmd -s unregister /path/to/vmx

and then manually delete the VM directory, the problem is on the MUI (VI Client or Virtual Center) the VM is left orphaned. I'm currently testing ability of sharing a single VMDK across the same ESX Host and by accidently removing from disk, it removes the linked reference of the VMDK. Removing from inventory is safer and you can remove the disk files manually, the problem is I'm creating dozen of VMs at once and it would be nice to be able to run a single commandline to do the same without the affects of "removing from disk"

I've tried to look at some of the vmware-vim-dm/vimsh commands and I haven't been able to find anything that will remove it from inventory.

Any help would great, thanks in advanced.

Re: Commandline for removing VMs from "Inventory"

1. Jun 27, 2008 7:38 AM in response to: lamw
Click to view kjb007's profile Guru 5,476 posts since
Sep 18, 2006

Use powershell vi toolkit. Simple one-two line script.

Get-vm vm_to_remove |remove-vm -DeleteFromDisk

Re: Commandline for removing VMs from "Inventory"

3. Jun 27, 2008 3:25 PM in response to: lamw
Click to view appk's profile Expert 182 posts since
Apr 6, 2008
With the command: vmware-cmd -s unregister <vm-cfg-path>
You'll need to restart the services mgmt-vmware and vmware-vpxa in-order for the front-end to pickup the change.

Or,
The inventory is stored in the file /etc/vmware/hostd/vmInventory.xml
I suppose you could try deleting the relevent entry then restarting the mgmt-vmware and vmware-vpxa services.
I haven't tried this so I don't know if it works.

Or,
vimsh appears to have a command called vimsvc/unregister
Not sure what it does but it sounds promising.

Message was edited by: appk

Re: Commandline for removing VMs from "Inventory"

5. Jun 28, 2008 4:32 AM in response to: lamw
Click to view appk's profile Expert 182 posts since
Apr 6, 2008
When I unregister a VM from the command line, it gets removed from the front-end of ESX but not from VirtualCenter.
i.e. if you are connected directly to the ESX using the VI Client, it will update correctly.

In VirtualCenter it shows as orphaned. Is this what your referring to?

This happens because the VC database is not aware of the unregister because the command was issued on the ESX server.
There is no command on ESX to unregister a VM through VirtualCenter but you can use the VI Perl Toolkit or one of the other API's.

The VI Perl Toolkit comes with a script for unregistering VM's through VirtualCenter:
http://www/support/developer/viperltoolkit/viperl15/doc/vmregister.html
This worked for me with: perl vmregister.pl --url https://vchost/sdk/vimService --username administrator --password blah --operation unregister --vmname TESTVM

Re: Commandline for removing VMs from "Inventory"

6. Jun 28, 2008 6:05 AM in response to: lamw
Click to view kjb007's profile Guru 5,476 posts since
Sep 18, 2006
The software messed up the command line. The last bit about deletefromdisk is optional. The command by itself will remove from inventory.

-KjB

Re: Commandline for removing VMs from "Inventory"

10. Sep 28, 2008 3:57 AM in response to: lamw
Click to view JasonW's profile Novice 5 posts since
Jul 19, 2005

If "vmware-vim-cmd vmsvc/ungregister <VM_ID> worked for the orphaned VM, how do you get the VM_ID of a machine in an orphaned state, as it would not be powered on?

vm-support -x will only show the vmid of running VMs.

Re: Commandline for removing VMs from "Inventory"

12. Sep 29, 2008 12:27 AM in response to: lamw
Click to view JasonW's profile Novice 5 posts since
Jul 19, 2005
Thanks for the info, I was able to get the vmid of the machine. However the 'vmware-vim-cmd vmsvc/unregister <vm_id>" command still left the VM in a orphaned state.

Re: Commandline for removing VMs from "Inventory"

14. Sep 30, 2008 12:36 PM in response to: lamw
Click to view JasonW's profile Novice 5 posts since
Jul 19, 2005

Thanks for your help but this still does not work for me, and leaves the VM in an orphaned state in the VI client. I am running ESX3.5 u2. I have tried this on another VM and has the same result.

I may open a support call with VMware and see what they suggest.

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities