Determining a virtual machine's associated vmx/.vmtx file
search cancel

Determining a virtual machine's associated vmx/.vmtx file

book

Article ID: 343191

calendar_today

Updated On:

Products

VMware vCenter Server VMware vCenter Server 7.0 VMware vCenter Server 6.0 VMware vCenter Server 8.0

Issue/Introduction

Symptoms:

  • Adding a virtual machine to the vCenter Server inventory fails.
  • Cannot add a virtual machine to the vCenter Server inventory.
  • You see the error:

    A virtual machine or template having the same name is already registered. Server Error: The specified key, name, or identifier already exists.

Environment

VMware vCenter Server 6.0.x
VMware vCenter Server 6.7.x
VMware vCenter Server 7.0.x
VMware vCenter Server 5.5.x
VMware vCenter Server 6.5.x
VMware vCenter Server 8.0.x

Cause

This issue occurs if the .vmx/.vmtx file you are trying to register already exists within vCenter Server. If you do not see a virtual machine by this name, the virtual machine's display name has likely been changed to something different from the filename. If you have many virtual machines, it can be difficult to determine which virtual machine or template name is using this .vmx/.vmtx file.

Resolution

To generate a list of virtual machine names, the associated .vmx/.vmtx files, and their locations:
 
Note: You require access to run a query against the vCenter Server database from within SQL Management Studio, or a similar tool for non-Microsoft databases.
  1. Click the New Query button within SQL Management studio.
  2. In the query editor, run this query:

if it is vPostgres 

log-into vcdb using 
/opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres

Execute the below command, this command is safe and will give only output so no need to take a vcdb backup. 

VCDB=# 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;
       VM Name       |                                          File Name / PATH
---------------------+----------------------------------------------------------------------------------------------------
 vm1          | ds:///vmfs/volumes/5ba12e8e-########-####-########bf1/vm1/vm1.vmx
 vm2          | ds:///vmfs/volumes/5ba12e8e-d########-####-########f1/vm2/vm2.vmx

 

use VIM_VCDB;
 
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

The query returns a list similar to:

Note: This list shows all virtual machines and templates and their associated file. Datastores are denoted by their UUID, not by their friendly name.
 
  VM Name File Name / Path
1 VM1 sanfs://vmfs_uuid:4e0922a4-########-####-########255/VM1/VM1.vmx
2 VM2 sanfs://vmfs_uuid:4e092191-########-####-########66/VM2/VM2.vmtx