Useful commands for managing VMs and vSwitches from ESX console. If the command has been executed successfully there will be no output returned to screen (no output = success!!!).
If a command is not complete and you press enter it will return all the options available (equivalent of ? on Cisco).
esxcliSee all options
esxcli network ipSee ip options
Networking
Interface and vSwitch commands
esxcli network ip interface listList vmkernel interfaces and their config
esxcli network nic listDisplay listing of physical adapters and link state
esxcli network ip interface ipv4 getSee list of VMK IPs
esxcli network vswitch standard portgroup listList port groups
esxcli network vswitch standard listList current vswitch config
esxcli network vswitch dvs vmware listList Distributed Switch config
esxcfg-vswitch -lCheck the uplinks and VM interfaces on a DvS
Add or remove network cards (vmnics) to or from a DvS:
esxcli network vswitch dvs vmware listList Distributed Switch config
esxcfg-vswitch -Qvmnic -VdvPort_ID_of_vmnic dvSwitch Unlink/remove a DvS uplink
esxcfg-vswitch -Pvmnic -Vunused_dvPort_ID dvSwitch Add a DvS uplink
Create vSwitch and add NIC and remove a Port-group
esxcli network vswitch standard list
esxcli network vswitch standard add vswitch-name=vSwitch1
esxcli network vswitch standard uplink add uplink-name=vmnic32 vswitch-name=vSwitch
Create port-group and assign a VLAN
esxcli network vswitch standard portgroup list
esxcli network vswitch standard portgroup add -ppg_name -vvSwitch1
esxcli network vswitch standard portgroup set -ppg_name -v10
To remove port-groups. When I tried deleting the default VM Network port-group would get the error ‘Host did not have any virtual network defined’ when deploying an OVF. Not sure if can delete this or it needs to stay.
esxcli network vswitch standard portgroup remove -ppg_name -vvSwitch0
Create vmkernal interface and give it IP details
esxcli network ip interface list
esxcli network ip interface add interface-name=vmk1 portgroup-name=mgmt
esxcli network ip interface ipv4 set interface-name=vmk1 ipv4=10.10.10.55 netmask=255.255.255.0 type=static
esxcli network ip interface set -e true -ivmk1 To enable the interface
Add a default route or static route
esxcli network ip route ipv4 list
esxcli network ip route ipv4 add -ggateway -n default
esxcli network ip route ipv4 add -ggateway -nnetwork/mask
Virtual Machines
Move Datastore and register the VMs. When discovering a DS it will show in the directory /vmfs/volumes], it can take 5 minutes to populate. For the VMs to appear in the GUI inventory they each need to be re-registered (.vmx file).
esxcli scsi adapter listCheck the iSCSI adapter name, usually vmhba3x
esxcli iscsi adapter discovery rediscover -Avmhba34 Discover the DS
vim-cmd vmsvc/register/vmfs/volumes/ds2/vm_name/vm_name.vmx To re-register a VM, reference the VMs .vmx file
vim-cmd vmsvc/getallvmsList all registered VMs
vim-cmd vmsvc/unregister/vmfs/volumes/ds2/vm_name/vm_name.vmx To un-register a VM
Powering on, off or restarting VMs. First need to get the VMID and then that is referenced in the vim-cmd.
vim-cmd vmsvc/getallvmsList all VMIDs
vim-cmd vmsvc/getallvms | grepvm name Get a specific VMs VMID
esxcli vm process listList all powered on VMs
vim-cmd vmsvc/power.getstatevm_name Check the power state of the VM
vim-cmd vmsvc/power.onvmid Power on a vm
vim-cmd vmsvc/reloadVmid Restart a vm
THis can also be done using esxcli, but rather than using the VMID need the ‘World ID’. soft is the most graceful, hard performs an immediate shutdown and force should only be used as a last resort.
esxcli vm process list | grep -C5vm_name Find the World ID of the VM
esxcli vm process kill -t softor hardor force -wWorldNumber Power on or off the VM
Change HW version. Need to unregister it, change the version in the .vmx file and re-register it.
vim-cmd vmsvc/getallvmsList all registered VMs
vim-cmd vmsvc/unregister/vmfs/volumes/ds2/vm_name/vm_name.vmx unregister vm
vi/vmfs/volumes/ds2/vm_name/vm_name.vmx Edit the 'virtualHW.version' dictionary
vim-cmd solo/registervm/vmfs/volumes/ds2/vm_name/vm_name.vmx
Some other useful vim-cmd commands for editing VMs.
Other
Globally enable or disable the ESX firewall
esxcli network firewall set -e false
esxcli network firewall set -e true
Hardrive/ Storage
esxcli storage filesystem listList all mounted volumes, can unmount/ mount here
ls -lha /vmfs/devices/disks/See all hdds & partitions
esxcli storage nmp device listList all hdds