vim-cmd Commands

Using vim-cmd commands to manage ESXi hosts and VMs:

  1. Get VM Information
  2. Manage the ESXi Hosts
  3. Register a VM
  4. Power On a VM
  5. Unregister a VM

1: Get VM Information
You use vim-cmd commands to list information about the VMs that run on the esxi- host. You also use vim-cmd commands to change the power state of a VM.

  1. Use MTPuTTY to establish an SSH session with esxi.
  2. List the commands available under the vmsvc namespace.
    vim-cmd vmsvc
  1. List and review information about the VMs that are registered on the ESXi host.
    a. List information about the VMs running on the ESXi host.
    vim-cmd vmsvc/getallvms
  1. b. Record the VMID for the VM.
  1. Get the configuration of the VM running on the ESXi host.
    vim-cmd vmsvc/get.guest
  1. List the power-related commands under the vmsvc namespace.
    vim-cmd vmsvc/power
  1. View the power state of a VM with VMID=2.
    vim-cmd vmsvc/power.getstate
  1. Power off VM with VMID=29.
    vim-cmd vmsvc/power.off the VM.
  1. View the power state of VM with VMID=29.
    vim-cmd vmsvc/power.getstate
  1. Wait for the OS and VMware Tools services to fully start and then get the configuration of VM with VMID=29 running on the ESXi host.
    vim-cmd vmsvc/get.guest 29 | less
  1. From the command output, determine the disk capacity for this VM.

2: Manage the ESXi Hosts
You use vim-cmd commands to place the esxi host in maintenance mode, take it out of maintenance mode, and view host configuration information.

  1. Place esxi in maintenance mode.
    vim-cmd hostsvc/maintenance_mode_enter

  1. The operation times out because a VM is powered on and the host does not belong to a fully automated DRS cluster.
  1. Use vim-cmd to shut down the VM.
  2. Place esxi in maintenance mode.
  3. View the configuration of host esxi.
    vim-cmd hostsvc/hostsummary | less
  1. In the command output, find information about the ESXi host’s memory size, CPU information, number of NICs, and number of HBAs.
  1. Take sa-esxi-03 out of maintenance mode.
    vim-cmd hostsvc/maintenance_mode_exit

3: Register a VM
You use vim-cmd commands to register the VM with the host.
The VM files are on a datastore.

  1. Register VM with the vCenter Server system.
    vim-cmd solo/registervm /vmfs/volumes/Shared3/Win-11/Win-11.vmx
    The command returns the VMID of the newly registered VM.
  1. List all the VMs on Esxi.
    vim-cmd vmsvc/getallvms
    registered VM should appear in the list.
  2. Verify that VM appears in the vSphere Client inventory.

5: Unregister a VM
You use vim-cmd commands to unregister the Win-11 VM from the host and the vCenter Server system.

  1. Use vim-cmd to power off the VM.
    The VM must be powered off before it can be unregistered.
  1. Unregister the VM.
    vim-cmd vmsvc/unregister
  1. Verify that VM is unregistered.
    vim-cmd vmsvc/getallvms
  1. the VM should not appear in the list.
  2. View VM in the vSphere Client inventory.
    VM should be in an orphaned state. An orphaned VM is one that exists in the vCenter Server database but is no longer present on the ESXi host.

  1. a. If the VM is not in an orphaned state, refresh the vSphere Client to update the navigation pane.
  2. In the vSphere Client, remove the VM from the Hosts and Clusters inventory.

About the author

Mosab Shaker

I stand at the forefront of the fastest moving technology trends like Digital Transformation, computer virtualization ,networking and security. I spent the past tenth years evangelizing an industry-wide shift to the co location in the MENA by promoting virtualization and cloud services many Customers . With a unique mix of knowledge about different industries, businesses, and technologies

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *