How to find the Virtual Machines on a Datastore from ESXi CLI When vCenter and Host UI Are Inaccessible
search cancel

How to find the Virtual Machines on a Datastore from ESXi CLI When vCenter and Host UI Are Inaccessible

book

Article ID: 407797

calendar_today

Updated On:

Products

VMware vSphere ESX 8.x VMware vSphere ESX 7.x

Issue/Introduction

  • Unable to access vCenter Server or ESXi Host Client UI.

  • Need to identify which virtual machines (VMs) are located on a specific datastore.

  • Only SSH/CLI access (e.g., via PuTTY) to the ESXi host is available.

 

 

Environment

  • VMware vSphere ESXi 7.x, 8.x
  • Access to the ESXi host through SSH (PuTTY or equivalent)

Resolution

When vCenter Server and the ESXi Host Client are not accessible, you can use the ESXi CLI to identify the virtual machines stored on a datastore.
Note: Ensure that SSH is enabled on the ESXi host before attempting these steps.

1. Connect to the ESXi Host

  • Open PuTTY (or another SSH client).

  • Connect to the ESXi host using the management IP address.

  • Log in with the root account or another administrator account.

2. List Available Datastores

Run the following command to view all mounted datastores:

esxcli storage filesystem list

This command displays the datastore names, UUIDs, and mount points (e.g., /vmfs/volumes/datastore1).

3. Navigate to the Datastore

Change directory to the datastore:

cd /vmfs/volumes/<datastore_name> ls -l

Each folder generally corresponds to a VM and contains .vmx and .vmdk files.

4. Identify Virtual Machines on the Datastore

List all VM configuration files (.vmx) stored on the datastore:

find /vmfs/volumes/<datastore_name> -name "*.vmx"

Example output:

/vmfs/volumes/datastore1/Win2022/Win2022.vmx /vmfs/volumes/datastore1/LinuxVM/LinuxVM.vmx
 

5. Retrieve VM Display Names

To extract the configured display names from the .vmx files, run:

grep displayName /vmfs/volumes/<datastore_name>/*/*.vmx

Example output:

/vmfs/volumes/datastore1/Win2022/Win2022.vmx:displayName = "Windows Server 2022" /vmfs/volumes/datastore1/LinuxVM/LinuxVM.vmx:displayName = "Ubuntu-TestVM"

6. (Optional) Verify Registered and Running VMs

You can list all VMs currently registered on the ESXi host and map them to the datastore:

vim-cmd vmsvc/getallvms

This command displays VM IDs, VM names, and datastore paths.

 

Additional Information

If you know the datastore name, you may run the below command:

find /vmfs/volumes/<Datastore_name>/ -name "*.vmx" | sed 's#.*/##' | sed 's/\.vmx$//'

find /vmfs/volumes/<Datastore_name>/ -name "*.vmx" | sed 's#.*/##' | sed 's/\.vmx$//' | wc -l ----> This will get the total number of VMs on the specific datastore

find /vmfs/volumes/<datastore> -name "*.vmx" ---> list all the VM names presented on the datastore