10 ESXi vim-cmd commands I use every other day

1. Enter maintenance mode

vim-cmd hostsvc/maintenance_mode_enter

2. Exit maintenance mode

vim-cmd hostsvc/maintenance_mode_exit

Check the status of maintenance mode

esxcli system maintenanceMode  get
Disabled

3. View hardware information of the host such as server model, BIOS version, CPU etc.

 vim-cmd hostsvc/hosthardware | more
(vim.host.HardwareInfo) {
   systemInfo = (vim.host.SystemInfo) {
      vendor = "Cisco Systems Inc",
      model = "UCSC-C220-M4S",
      uuid = "0ea52b5d-a845-634b-b750-2bdbb44c1f67",
      otherIdentifyingInfo = (vim.host.SystemIdentificationInfo) [
         (vim.host.SystemIdentificationInfo) {
            identifierValue = " Unknown",
            identifierType = (vim.ElementDescription) {
               label = "Asset Tag",
               summary = "Asset tag of the system",
               key = "AssetTag"
            }
         },
(Truncated)

BIOS version

 vim-cmd hostsvc/hosthardware | grep -i bios
   biosInfo = (vim.host.BIOSInfo) {
      biosVersion = "C220M4.2.0.3d.0.111120141447",

CPU Features

 vim-cmd hostsvc/hosthardware | grep -A10 cpuFeature
         cpuFeature = (vim.host.CpuIdInfo) [
            (vim.host.CpuIdInfo) {
               level = 0,
               vendor = ,
               eax = "0000:0000:0000:0000:0000:0000:0000:1111",
               ebx = "0111:0101:0110:1110:0110:0101:0100:0111",
               ecx = "0110:1100:0110:0101:0111:0100:0110:1110",
               edx = "0100:1001:0110:0101:0110:1110:0110:1001"
            },
            (vim.host.CpuIdInfo) {
               level = 1,

4. Get a list of all VMs registered in a host

vim-cmd vmsvc/getallvms

Vmid   Name               File                    Guest OS               Version                         Annotation
1      VM1      [DATASTORE1] VM1/VM1.vmx         sles11_64Guest           vmx-10    vRealize Operations Manager Appliance
31     VM2      [DATASTORE1] VM2/VM2.vmx         rhel6_64Guest           vmx-08    Provisioned by VMware vCAC         
37     VM3      [DATASTORE1] VM3/VM3.vmx         windows8Server64Guest   vmx-10    test                               

To get a list of running VMs

 esxcli vm process list
VM1
   World ID: 1540983
   Process ID: 0
   VMX Cartel ID: 1540982
   UUID: 42 37 d1 3e ac 6a d0 44-f7 45 e3 cb b6 42 44 a6
   Display Name: VM1
   Config File: /vmfs/volumes/5445815b-0eea5758-83bb-5cf3fcb76e8c/VM1/VM1.vmx

VM2
   World ID: 107981
   Process ID: 0
   VMX Cartel ID: 107980
   UUID: 42 32 39 7f 72 fa 4a 50-bf ee fd 8e 99 47 e4 75
   Display Name: VM2
   Config File: /vmfs/volumes/553e5ee0-6923ec48-3b08-5cf3fcb76e8c/VM2/VM2.vmx

VM3
   World ID: 5974143
   Process ID: 0
   VMX Cartel ID: 5974142
   UUID: 42 37 75 ac bd d0 ef 71-9f 84 b1 80 dd db a6 3c
   Display Name: VM3
   Config File: /vmfs/volumes/553e5ee0-6923ec48-3b08-5cf3fcb76e8c/VM3/VM3.vmx

5. View guest details such as IP address, Network, VMware Tools etc.

vim-cmd vmsvc/get.guest ID

Example:

vim-cmd vmsvc/get.guest 1
Guest information:

(vim.vm.GuestInfo) {
   toolsStatus = "toolsOk",
   toolsVersionStatus = "guestToolsUnmanaged",
   toolsVersionStatus2 = "guestToolsUnmanaged",
   toolsRunningStatus = "guestToolsRunning",
   toolsVersion = "2147483647",
   toolsUpdateStatus = (vim.vm.GuestInfo.ToolsUpdateStatus) null,
   guestId = "sles11_64Guest",
   guestFamily = "linuxGuest",
   guestFullName = "SUSE Linux Enterprise 11 (64-bit)",
   hostName = "vm1.local.example.com",
   ipAddress = "192.168.1.148",
   net = (vim.vm.GuestInfo.NicInfo) [
      (vim.vm.GuestInfo.NicInfo) {
         network = "192.168.1.0_255.255.255.0",
         ipAddress = (string) [
            "192.168.1.148",
(Truncated..)

6. Get information about directly connected network devices such as switch ports, vlan etc. which are advertised by the network device using CDP.

 vim-cmd hostsvc/net/query_networkhint
(vim.host.PhysicalNic.NetworkHint) [
   (vim.host.PhysicalNic.NetworkHint) {
      device = "vmnic0",
      subnet = (vim.host.PhysicalNic.NetworkHint.IpNetwork) [
         (vim.host.PhysicalNic.NetworkHint.IpNetwork) {
            vlanId = 10,
            ipSubnet = "192.168.1.0-192.168.1.173"
         },
         (vim.host.PhysicalNic.NetworkHint.IpNetwork) {
            vlanId = 20,
            ipSubnet = "192.168.2.113-192.168.2.113"
         }
      ],
      connectedSwitchPort = (vim.host.PhysicalNic.CdpInfo) {
         cdpVersion = 2,
         timeout = 60,
         ttl = 162,
         samples = 120923,
         devId = "SWITCH_NAME",
         address = "192.168.1.250",
         portId = "Ethernet131/1/3",
         deviceCapability = (vim.host.PhysicalNic.CdpDeviceCapability) {
            router = false,
            transparentBridge = false,
            sourceRouteBridge = false,
            networkSwitch = true,
            host = false,
            igmpEnabled = true,
            repeater = false
(Truncated..)

7. Run network query for specific physical NIC

vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicXY

Example:

 vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnic0
(vim.host.PhysicalNic.NetworkHint) [
   (vim.host.PhysicalNic.NetworkHint) {
      device = "vmnic0",
      subnet = (vim.host.PhysicalNic.NetworkHint.IpNetwork) [
         (vim.host.PhysicalNic.NetworkHint.IpNetwork) {
            vlanId = 10,
            ipSubnet = "192.168.1.0-192.168.1.173"
         }
      ],
      connectedSwitchPort = (vim.host.PhysicalNic.CdpInfo) {
         cdpVersion = 2,
         timeout = 60,
         ttl = 152,
         samples = 120925,
         devId = "SWITCH_NAME",
         address = "192.168.1.250",
         portId = "Ethernet131/1/3",
         deviceCapability = (vim.host.PhysicalNic.CdpDeviceCapability) {
            router = false,
            transparentBridge = false,
            sourceRouteBridge = false,
            networkSwitch = true,
            host = false,
            igmpEnabled = true,
            repeater = false
         },
         softwareVersion = "Cisco Nexus Operating System (NX-OS) Software, Version 5.2(1)N1(6)",
         hardwarePlatform = "N5K-C5548UP",
         ipPrefix = "0.0.0.0",
         ipPrefixLen = 0,
         vlan = 888,
         fullDuplex = true,
         mtu = 1500,
         systemName = "SWITCH_NAME",
         systemOID = "1.3.6.1.4.1.xxxxxxxxx",
         mgmtAddr = "192.168.1.3",
         location = "snmplocation"
      },
      lldpInfo = (vim.host.PhysicalNic.LldpInfo) null,
   }
]

8. Enable vMotion on vmk0 VMkernal interface

vim-cmd  hostsvc/vmotion/vnic_set vmk0

9. Stop ssh service

vim-cmd hostsvc/stop_ssh 

10. Start ssh service

vim-cmd hostsvc/start_ssh
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s