This article provides instructions for removing orphaned virtual machines and/or templates from the vCenter Server database. This procedure is used when the objects cannot be removed via the vSphere Client.
Symptoms:
vim-cmd vmsvc/getallvms is run on the ESXi host CLI
VMware vCenter Server 7.x
VMware vCenter Server 8.x
VMware vCenter Server 9.0.x
Metadata inconsistency occurs when a virtual machine or datastore is removed directly from an ESXi host or storage layer while vCenter Server is unaware of the change; leaving residual entries in the vCenter Server database.
Example Output:
VCDB=# select * from vpx_entity where name like '%vcsa%'; id | name | type_id | parent_id --------+---------------------+------------+------------ 0000 | vcsa(orphaned) | # | #
#### with the numeric id found previously:delete from VPX_DVPORT where connectee='vm-<VM_ID>';\qReview Snapshot Best practices for vCenter Server Virtual Machines before performing database maintenance.