Using the vim-cmd Tool

Reading Time: 6 minutes

Using the vim-cmd Tool is an article that explains some useful commands with the tool vim-cmd for troubleshooting hosts and VMs in your virtual environment.

Basically, the VMware Infrastructure Management command (vim-cmd) is a CLI (Command Line Interface) tool for managing ESXi hosts and their VMs from the command line. Some important things about this tool:

  • Communicates with the hostd daemon to perform tasks on the ESXi host (to remember, the hostd daemon is an important daemon/service that runs on every ESXi host)
  • It has several command categories (we will show some basic and fundamental ones in this article)

For curiosity, the command “/sbin/vim-cmd” is a symbolic link for the hostd daemon:

To see all vim-cmd categories:

Under each category, we can see the available subcommands:

Why should I use the vim-cmd tool?

So, the vim-cmd tool is an excellent tool for troubleshooting hosts and VMs issues using the command line interface. In my personal opinion, for people that are familiar with the command line, this tool will help a lot. If you are an Infrastructure or Virtualization Administrator, I believe that you need to know a little about this excellent tool.

Below, we will show some practical usages for the vim-cmd tool:

vim-cmd vmsvc/getallvms
vim-cmd vmsvc/power.getstate
vim-cmd vmsvc/get.guest
vim-cmd vmsvc/get.snapshot
vim-cmd vmsvc/snapshot.get
vim-cmd vmsvc/get.networks
vim-cmd vmsvc/get.datastores
vim-cmd vmsvc/power.shutdown
vim-cmd vmsvc/power.off
vim-cmd vmsvc/power.on
vim-cmd vmsvc/snapshot.removeall
vim-cmd vmsvc/snapshot.create
vim-cmd hostsvc/hostsummary
vim-cmd hostsvc/maintenance_mode_enter
vim-cmd hostsvc/maintenance_mode_exit
vim-cmd hostsvc/net/info
vim-cmd hostsvc/net/vnic_info

vim-cmd vmsvc/getallvms (command list)

The command “vim-cmd vmsvc/getallvms” lists all VMs on a host. For example:

Look at some important this here:

Vmid = This is a VM ID. This number is used to identify the VM on the ESXi host. Each VM has your VM ID number;
Name = VM Name (this is the same name that we can see on the vSphere Client Inventory);
File = Here we have a lot of useful information. Look for the VM “linux-a-03”. The “[Private-01]” is the Datastore Name that this VM is using. Later, we have the name of the VM configuration file (.vmx);
Guest OS = GuestOS type;
Version = Version of Virtual VM Hardware;
Annotation = Some annotation or description (when existing).

vim-cmd vmsvc/power.getstate (command list)

This command “vim-cmd vmsvc/power.getstate” shows the VM status. We can use this command to check if a specific VM is powered on or not.

Firstly, we need to get the VMID and then execute the command with this VMID.
In this example, the VM “linux-a-03” with VMID 12 is running:

vim-cmd vmsvc/get.guest (command list)

If a VM is running and has the VMware Tools installed, we can get a lot of details about this VM (VMware Tools version, IP address, Mac Address, etc). The command “vim-cmd vmsvc/get.guest” can be used for that. Look, we need to type the VMID too:

vim-cmd vmsvc/get.snapshot (command list)

This command is very useful to check if a specific VM has snapshots. We need to type the VMID for the VM that we need to get details. For example:

In this case, we have two active snapshots. The information “(vim.vm.SnapshotTree)” delimited each snapshot in the snapshot tree.

vim-cmd vmsvc/snapshot.get (command list)

Another way to see information about snapshots in a specific VM is with the command “vim-cmd vmsvc/snapshot.get”. We need to type the VMID of the VM that we need to see these details, for example:

vim-cmd vmsvc/get.networks (command list)

To get the Port Group name for a specific VM, the command “vim-cmd vmsvc/get.networks” can help in this way. So, we need to type the VMID:

vim-cmd vmsvc/get.datastores (command list)

To see what datastore a specific VM is using, the command “vim-cmd vmsvc/get.datastores” can show this information. We need to type the VMID:

vim-cmd vmsvc/power.shutdown (command list)

To shut down a specific VM using the VMware Tools (Shut down GuestOS), the command “vim-cmd vmsvc/power.shutdown” can be used for that. Again, we need to type the VMID:

vim-cmd vmsvc/power.off (command list)

This command can be used to shut down the VM too. But it does not use the VMware Tools for this operation (it applies a Power Off – without properly shutting down the operating system):

Note: In the above example, we received this message because this VM is already powered off 😉

vim-cmd vmsvc/power.on (command list)

In addition to turning off a VM, we can apply power on a specific VM. The command “vim-cmd vmsvc/power.on” does that. In this example, we are powering up the VMID 12:

vim-cmd vmsvc/snapshot.removeall (command list)

At the same time that we can see snapshot details from the command line, we can remove all snapshots as well. To do that, the command “vim-cmd vmsvc/snapshot.removeall” can be used.

This command will remove all snapshots (delete all) for the VMID 12:

vim-cmd vmsvc/snapshot.create (command list)

Another useful option is to create a VM snapshot from the command line. We can achieve it with the command “vim-cmd vmsvc/snapshot.create”:

In this case, look for the command syntax:

12 = VMID
Snap01 = Snapshot’s name
Test-Snap01 = Snapshot’s description
1 = Include memory. If you do not need to include memory, type 0
0 = Enable or Disable the Quisce option

vim-cmd hostsvc/hostsummary (command list)

This command is useful to get details from a specific ESXi host. Examples of details that we can grab with this command:

  • Vendor name
  • Model
  • Host’s UUID
  • Connection State
  • Name/Hostname
  • OS version and build
  • Validate if the host is in Maintenance Mode
  • etc

To get full details:
vim-cmd hostsvc/hostsummary | less

To get specific detail, we can use the same command, filtering the output with ” | grep”. Below are some examples:

vim-cmd hostsvc/hostsummary | grep -i vendor
vim-cmd hostsvc/hostsummary | grep -i model
vim-cmd hostsvc/hostsummary | grep -i uuid
vim-cmd hostsvc/hostsummary | grep -i connectionState
vim-cmd hostsvc/hostsummary | grep -i name
vim-cmd hostsvc/hostsummary | grep -i version
vim-cmd hostsvc/hostsummary | grep -i build

vim-cmd hostsvc/hostsummary | grep -i maintenancemode

For example, to check if the ESXi host is in maintenance mode:

vim-cmd hostsvc/maintenance_mode_enter (command list)

This command is very useful to put the ESXi host in maintenance mode:

In this example, the ESXi hosts entered into maintenance mode normally. But if it does not occur, you need to investigate the root cause of that. For example: Are there any VMs running in this ESXi host? The DRS service is enabled? Etc.

vim-cmd hostsvc/maintenance_mode_exit (command list)

So, to exit from maintenance mode, we can run the following command:

vim-cmd hostsvc/net/info (command list)

This command shows a lot of details about the host’s networking. For example, we can see the names of Virtual Standard Switches, Virtual Distributed Switches, MTU value, Port Group detail, etc:

For example, to get the VSS names:
vim-cmd hostsvc/net/info | grep -i vswitchName

To get the DVS names:
vim-cmd hostsvc/net/info | grep -i dvsName

vim-cmd hostsvc/net/vnic_info (command list)

With this command, we can get details about all VMkernels interfaces. To get all VMkernels interfaces and their IP address, we can run the below command:

We have a lot of possibilities with the tool “vim-cmd”. I would like to share an excellent guide with a lot of details and examples about this tool:
https://communities.vmware.com/wbsdv95928/attachments/wbsdv95928/502/138/1/Quick%20Tutorial%20for%20vim-cmd%20commands.pdf

And also, the below VMware KB is very interesting:
https://kb.vmware.com/s/article/2012964