Attempts to add or register a virtual machine to the vCenter Server inventory fail.
The vSphere Client displays the following error message during the registration process: A virtual machine or template having the same name is already registered. Server Error: The specified key, name, or identifier already exists.
This issue occurs if the .vmx (virtual machine) or .vmtx (template) file being registered is already associated with an existing entity within the vCenter Server inventory.
If a virtual machine by this name is not visibly present in the vSphere Client, the virtual machine's display name has likely been modified and no longer matches its underlying datastore filename. In environments with a large virtual machine inventory, locating the exact virtual machine or template utilizing the locked configuration file can be challenging.
To generate a comprehensive mapping of virtual machine inventory names to their associated .vmx or .vmtx file paths and datastore locations, you must query the vCenter Server PostgreSQL database (VCDB).
Caution: While the query provided below is a safe, read-only operation, it is strongly recommended to ensure a valid file-based backup of the vCenter Server Appliance exists before accessing the vCenter Database via the command-line interface.
Establish an SSH session to the vCenter Server Appliance (vCSA) and authenticate as the root user.
If prompted, type shell to launch the vCenter Server bash shell.
Access the vCenter PostgreSQL database (VCDB) by executing the following command:/opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
Execute the following read-only SQL query to output the mapping of virtual machines to their file paths: SELECT vpx_entity.Name AS "VM Name", vpx_vm.file_name AS "File Name / PATH" FROM vpx_vm INNER JOIN vpx_entity ON vpx_vm.id = vpx_entity.id ORDER BY vpx_entity.name;
To filter the output and search for a specific virtual machine name or configuration file, append a WHERE clause using the ILIKE operator for a case-insensitive search. Replace YOUR_VM_NAME with the target string: SELECT vpx_entity.Name AS "VM Name", vpx_vm.file_name AS "File Name / PATH" FROM vpx_vm INNER JOIN vpx_entity ON vpx_vm.id = vpx_entity.id WHERE vpx_entity.Name ILIKE '%YOUR_VM_NAME%';
Expected Output Example:
VM Name | File Name / PATH
---------------------+----------------------------------------------------------------------------------------------------
Database-Server-01 | ds:///vmfs/volumes/5ba12e8e-########-####-########bf1/DB-Server-Old-Name/DB-Server-Old-Name.vmx
Web-Server-02 | ds:///vmfs/volumes/5ba12e8e-########-####-########bf1/Web-Server-02/Web-Server-0