Unregister invalid VMs using ESXi command-line
If a VM is deleted at vCenter when host is disconnected and same information is not synced with ESXi host properly, then VM might appear in invalid state at ESXi host. Also if VM is deleted at data-store level by deleting .vmx file but not using proper VM delete option then it might show up as invalid VM at ESXi level.
To unregister (similar to remove from inventory for vCenter) such VMs use:
- Login into ESXi web console (vsphere-client) and verify that invalid VM is present and that it is not getting deleted using ESXi console.
- SSH to ESXi host
- List all registered VMs using:
- vim-cmd /vmsvc/getallvms
- Unregister particular VM using:
- vim-cmd /vmsvc/unregister <id>
- Verify from ESXi web console (vsphere-client) that invalid VM is no longer listed
- After this if the same VM shows up in vsphere-inventory with path /volumes/vmfs/<vm-id> then wait for 5-10min. After 5-10min, "Remove from Inventory" option should come in vCenter for the corresponding VM.
- Note that above steps only remove the VM from vSphere or vCenter. If the VM was not deleted from datastore its disk and configuration files might still be present and need to be deleted separately.