vimsh is an interactive shell buffer. It allows execution of shell commands in a vim buffer, without having to suspend the vim session. It provides an interactive command line session. 

In the context of VMware ESX it has been implemented as an API for the ESX host agent. VI Client via the ESX host and/or VirtualCenter, and can report and configure numerous items. Changes made by using this command appear in the VI Client console at normal refresh schedules.

What is vmware-vim-cmd?

Introduced in ESX 3.5 this command is a 'wrapper' for the vimsh shell. It simplifies the command and means that vimsh can be run without having to enter and exit the shell and use previously documented command switches and "quotes".

Why use it?

There is some overlap from current Service Console tools, such as vmware-cmd and esxcfg-* but this API also provides some excellent reporting options and offers new ways to tailor and automate scripting tasks.

The above definitions are the work/findings of Xtravirt and their initial publishing's on VMware vimsh.

Versions of VMware's vimsh:

ESX 3.0.x+

/usr/bin/vimsh -n -e "command"

ESX 3.5+

/usr/bin/vimsh -n -e "command"
/usr/bin/vmware-vimsh "command"
/usr/bin/vmware-vim-cmd "command"

ESX 4.+

/usr/bin/vimsh -n -e "command"
/usr/bin/vmware-vimsh "command"
/usr/bin/vmware-vim-cmd "command"

ESXi 3.5+

/bin/vim-cmd "command"

ESXi 4.0+

/bin/vim-cmd "command"

How to use vimsh?

To see the available commandset for a given "vimsh" release, you just execute the command normally on the shell.You'll be be brought into the interactive shell, you can hit "tab" to see the various options and flags.

When running specific commands on Virtual Machine(s), vimsh requires the internal Virtual Machine Id called "VmId" which needs to be passed as a parameter, the VmId for a given VM can be located when running vmsvc/getallvms as shown below. Unlike the traditional vmware-cmd, where you pass in the .vmx path of a VM, you need to extract the VmId if you're looking to automate/script any tasks using vimsh

General "vimsh" commands for all ESX versions:
Substitute the appropriate "vimsh" for the version of ESX

Find all VMs currently registered to ESX host:
[vimsh|vmware-vimsh|vmware-vim-cmd] vmsvc/getallvms

vimsh -n -e "vmsvc/getallvms"

vmware-vimsh -n -e "vmsvc/getallvms"

vmware-vim-cmd "vmsvc/getallvms"

All VMs output for ESX 3.0.x+
[root@appalachian root]# vmware -v
VMware ESX Server 3.0.0 build-27701

[root@appalachian root]# vimsh -n -e "vmsvc/getallvms"
[2008-12-23 10:18:55.989 'App' 3076464768 info] Current working directory: /usr/lib/vmware/hostd
[2008-12-23 10:18:55.990 'BaseLibs' 3076464768 info] Using system libcrypto, version 90709F

[2008-12-23 10:18:56.021 'BaseLibs' 6237104 warning] [Vmdb_Unset] Unsetting unknown path: /vmomi/

VmId : 16
Name : Microsoft Windows XP Professional
File : [appalachian-local-U320.Storage] /Quentin/Quentin.vmx
GuestOS : winXPProGuest
Annotation :

All VMs output for ESX 3.5+ / ESXi 3.5+
[root@himalaya lamw]# vmware -v
VMware ESX Server 3.5.0 build-110268

[root@himalaya lamw]# vmware-vim-cmd vmsvc/getallvms
Vmid Name File Guest OS Version Annotation
1040 STA202H [himalaya-local-SAS.VMStorage] STA202H/STA202H.vmx winXPProGuest vmx-04
1072 William-XP [himalaya-local-SAS.VMStorage] William-XP/William-XP.vmx winXPProGuest vmx-04
16 Bitsy [himalaya-local-SAS.VMStorage] Bitsy/Bitsy.vmx otherLinuxGuest vmx-04 MySQL FTP Database
1680 Quentin [himalaya-local-SAS.VMStorage] Quentin/Quentin.vmx winXPProGuest vmx-0

Register virtual machines - (functions just like vmware-cmd -s register /vmfs/volumes/......MY_VM.vmx)

[vimsh|vmware-vimsh|vmware-vim-cmd] solo/registervm /vmfs/volumes/......MY_VM.vmx

Register virtual machines and assign to specific resource pool

[vimsh|vmware-vimsh|vmware-vim-cmd] solo/registervm /vmfs/volumes/......MY_VM.vmx MACHINE_NAME cat /etc/vmware/hostd/pools.xml | grep "YOUR-RESOURCE-POOL-NAME" -A1 | grep "[objID]" | sed 's///;s/<\/objID>//g' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//'

vmware-vim-cmd solo/registervm /vmfs/volumes/olga-local-SAS.Storage/UCSB-GAUCHOS/UCSB-GAUCHOS.vmx UCSB-GAUCHOS cat /etc/vmware/hostd/pools.xml | grep "UCSB-DEV-RP" -A1 | grep "[objID]" | sed 's///;s/<\/objID>//g' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//'

Unregiseter virtual machines - (functions just like vmware-cmd -s unregister /vmfs/volumes/......MY_VM.vmx)

[vimsh|vmware-vimsh|vmware-vim-cmd] vmsvc/unregister [VmId]

Find LUN information regarding HBA Adapter, Storage Vendor, State, LUN ID, LUN UUID, portWWN, nodeWWN, pathState, TransportMode,etc.....

[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/storage/info | less

For HBA information only

[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/storage/hba_info

For datastore information only

[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/datastore/listsummary
[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/storage/fs_info

vdf -h equivalent

[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/datastore/listsummary | grep -E '(name|url|capacity|type)' | sed 's/,//g'

Create NFS Datastore as you would from VIC or VC

vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/datastore/nas_create [DISPLAY_NAME] [NFS_SERVER_IP] [MOUNT_PATH] [MODE(readwrite=0/readonly=1)]

[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/datastore/nas_create MY_NFS_DATASTORE /nfs/mount/point 0

Refresh various system attributes to show up on the VIC / VC, this helps when you automating tasks through scripts but don't refresh the GUI

[vimsh|vmware-vimsh|vmware-vim-cmd] internalsvc/refresh_consolenic
[vimsh|vmware-vimsh|vmware-vim-cmd] internalsvc/refresh_datastores
[vimsh|vmware-vimsh|vmware-vim-cmd] internalsvc/refresh_datastores
[vimsh|vmware-vimsh|vmware-vim-cmd] internalsvc/refresh_gateway
[vimsh|vmware-vimsh|vmware-vim-cmd] internalsvc/refresh_network
[vimsh|vmware-vimsh|vmware-vim-cmd] internalsvc/refresh_pnic
[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/refresh_firewall
[vimsh|vmware-vimsh|vmware-vim-cmd] hostsvc/refresh_services

ESX 3.0.x+ specific "vimsh" commands:

Standard VM operations:

vimsh -n -e "vmsvc/powerstate [VmId]"
vimsh -n -e "vmsvc/poweron [VmId]"
vimsh -n -e "vmsvc/poweroff [VmId]"
vimsh -n -e "vmsvc/suspend [VmId]"
vimsh -n -e "vmsvc/reset [VmId]"
vimsh -n -e "vmsvc/shutdown [VmId]"
vimsh -n -e "vmsvc/reboot [VmId]"
vimsh -n -e "vmsvc/hibernate [VmId]"
vimsh -n -e "vmsvc/createsnapshot [VmId] [snapshotName] [snapshotDescription] [includeMemory]"

vimsh -n -e "vmsvc/createsnapshot XXXX FIRST_SNAPSHOT MY_FIRST_SNAPSHOT_1"

vimsh -n -e "vmsvc/revertsnapshot [VmId] [snapshotLevel] [snapshotIndex]"

vimsh -n -e "vmsvc/revertsnapshot XXXX 1"

vimsh -n -e "vmsvc/removesnapshot [VmId] [removeChildren] [snapshotLevel] [snapshotIndex]"
vimsh -n -e "vmsvc/removeallsnapshots [VmId]"

Maintenance Mode for ESX host (unfortunately this command will not evacuate/VMotion your VMs to rest of the cluster)

vimsh -n -e "hostsvc/maintenance_mode_enter"
vimsh -n -e "hostsvc/maintenance_mode_exit"

Enable VMotion

vimsh -n -e "hostsvc/vmotion/vnic_set [vnic]"

Add/Remove vSwitch

vimsh -n -e "hostsvc/net/vswitch_add [vswitch_name]"

vimsh -n -e "hostsvc/net/vswitch_add vSwitch12"

vimsh -n -e "hostsvc/net/vswitch_add [vswitch_name]"

Add/Remove portgroup

vimsh -n -e "hostsvc/net/portgroup_add [options] [vswitch_name] [portgroup_name] [vlan_id]"

vimsh -n -e "hostsvc/net/portgroup_add --nicteaming-policy=loadbalance_ip vSwitch0 Admin_Portgroup 27"

vimsh -n -e "hostsvc/net/portgroup_remove [vswitch_name] [portgroup_name]"

ESX 3.5+ and ESXi 3.5+ specific "vimsh" commands:
Substitute either (vmware-vim-cmd) for ESX 3.5+ w/Service Console or (vim-cmd) for ESXi 3.5+

Standard VM operations:

vmware-vim-cmd vmsvc/power.getstate [VmId]
vmware-vim-cmd vmsvc/power.on [VmId]
vmware-vim-cmd vmsvc/ [VmId]
vmware-vim-cmd vmsvc/power.suspend [VmId]
vmware-vim-cmd vmsvc/power.reset [VmId]
vmware-vim-cmd vmsvc/power.shutdown [VmId]
vmware-vim-cmd vmsvc/power.reboot [VmId]
vmware-vim-cmd vmsvc/power.hibernate [VmId]
vmware-vim-cmd vmsvc/snapshot.create [VmId] [snapshotName] [snapshotDescription] [includeMemory]

vmware-vim-cmd "vmsvc/snapshot.create XXXX FIRST_SNAPSHOT MY_FIRST_SNAPSHOT_1"

vmware-vim-cmd vmsvc/snapshot.revert [VmId] [snapshotLevel] [snapshotIndex]

vmware-vim-cmd "vmsvc/snapshot.revert XXXX 1"

vmware-vim-cmd vmsvc/snapshot.removeall [VmId]
vmware-vim-cmd vmsvc/snapshot.remove [VmId] [removeChildren] [snapshotLevel] [snapshotIndex]
vmware-vim-cmd vmsvc/snapshot.get [VmId]

Maintenance Mode for ESX host (unfortunately this command will not evacuate/VMotion your VMs to rest of the cluster)

vmware-vim-cmd hostsvc/maintenance_mode_enter
vmware-vim-cmd hostsvc/maintenance_mode_exi

Enable VMotion (prior release used the VMotion portgroup name, as of 3.5, the command requires the VmkX value)

vmware-vim-cmd hostsvc/vmotion/vnic_set [vnic]

vmware-vim-cmd "hostsvc/vmotion/vnic_set" `esxcfg-vmknic -l | grep "VMKERNEL_PORTGROUP_NAME" | awk '{print $1}'

Add/Remove vSwitch

vmware-vim-cmd hostsvc/net/vswitch_add [vswitch_name]

vmware-vim-cmd hostsvc/net/vswitch_add vSwitch12

vmware-vim-cmd hostsvc/net/vswitch_remove [vswitch_name]

Add/Remove portgroup

vmware-vim-cmd hostsvc/net/portgroup_add [options] [vswitch_name] [portgroup_name] [vlan_id]

vmware-vim-cmd hostsvc/net/portgroup_add --nicteaming-policy=loadbalance_ip vSwitch0 Admin_Portgroup 27

vmware-vim-cmd hostsvc/net/portgroup_remove [vswitch_name] [portgroup_name]

For LUN information only

vmware-vim-cmd hostsvc/summary/scsilun

For HBA information only

vmware-vim-cmd hostsvc/summary/hba

For datastore information only

vmware-vim-cmd hostsvc/summary/fsvolume

List Promiscuous Mode, Mac Address Change and Forged Transmission @vSwitch or @portgroup level

vmware-vim-cmd hostsvc/net/vswitch_info | grep -E '(name|allowPromiscuous|macChanges|forgedTransmits)'

[root@himalaya backup_test]# vmware-vim-cmd hostsvc/net/vswitch_info | grep -E '(name|allowPromiscuous|macChanges|forgedTransmits)'
name = "vSwitch0",
allowPromiscuous = false,
macChanges = true,
forgedTransmits = true,
name = "vSwitch1",
allowPromiscuous = false,
macChanges = true,
forgedTransmits = true,
name = "vSwitch5",
allowPromiscuous = false,
macChanges = true,
forgedTransmits = true,

vmware-vim-cmd hostsvc/net/config | grep -E '(name|allowPromiscuous|macChanges|forgedTransmits)

Add Resource Pool

vmware-vim-cmd hostsvc/rsrc/create ha-root-pool pool1