Esxcli and vim-cmd commands for VM related queries

esxcli is a powerful command-line tool in VMware ESXi that allows you to manage various aspects of your virtual machines (VMs). It provides a wide range of commands to query and configure VM-related settings. Below are some commonly used esxcli commands for VM-related queries, along with examples:

1. List Virtual Machines:

To view a list of all virtual machines registered on the ESXi host:

esxcli vm process list

2. Display VM Information:

To display detailed information about a specific virtual machine:

esxcli vm process list | grep -i "Display Name"

Replace "Display Name" with the name of the virtual machine you want to query.

3. Power Operations (Start, Stop, Restart):

To power on a virtual machine:

esxcli vm process start --vmid=<VMID>

Replace <VMID> with the VM’s unique identifier (you can get it from the output of the previous esxcli vm process list command).

To power off a virtual machine:

esxcli vm process kill --type=soft --world-id=<WORLD_ID>

Replace <WORLD_ID> with the VM’s World ID (you can find it in the output of the previous esxcli vm process list command).

4. Check VM Tools Status:

To check the VM Tools status for a virtual machine:

esxcli vm process list | grep -i "Tools"

This will show you whether VM Tools are running, not running, or not installed for each VM.

5. Check VM Resource Allocation:

To view the CPU and memory allocation for a specific virtual machine:

vim-cmd vmsvc/get.summary <VMID> | grep -E "vmx|memorySizeMb"

Replace <VMID> with the VM’s unique identifier.

6. Query VM vCPUs and Cores:

To check the number of virtual CPUs and cores per socket for a virtual machine:

vim-cmd vmsvc/get.config <VMID> | grep -E "numvcpus|coresPerSocket"

Replace <VMID> with the VM’s unique identifier.

7. Query VM Network Adapters:

To list the network adapters attached to a virtual machine:

vim-cmd vmsvc/get.networks <VMID>

Replace <VMID> with the VM’s unique identifier.

8. List VM Snapshots:

To view the snapshots for a specific virtual machine:

vim-cmd vmsvc/snapshot.get <VMID>

Replace <VMID> with the VM’s unique identifier.

9. Query VM Disk Information:

To check the virtual disks attached to a virtual machine:

vim-cmd vmsvc/device.disklist <VMID>

10. Get VM IP Address:

To get the IP address of a virtual machine (requires VMware Tools running in the VM):

vim-cmd vmsvc/get.guest <VMID> | grep -i "ipAddress"

Replace <VMID> with the VM’s unique identifier.

Conclusion:

Using esxcli commands, you can easily query and manage various aspects of virtual machines on your VMware ESXi host. These commands provide valuable information about VMs, their configurations, resource allocation, and power states, allowing you to efficiently manage your virtual environment.

Leave a comment