ESXI cmd options
✍️This article provides a side-by-side comparison of performing virtual machine-related tasks using different VMware utilities and command line methods.⚠️
In these examples:🍭
- vcenter is your vCenter Server hostname
- esxhost is your ESX/ESXi hostname
- datastore is the display name of your datastore
- path_to_vmx_on_datastore is the path to the virtual machine's vmx file relative to the datastore on which it resides
- vm_name is the display name of a virtual machine
- path_to_vmx_file is the full path to a virtual machine's vmx file
- snapshot_name is the name given to a virtual machine snapshot
- guest_admin_user is a user account with administrative access within a virtual machine's guest OS
- guest_admin_password is the password for the account noted by guest_admin_user
- get the IP address of a host running VMware tools
#!/bin/bash
vim-cmd vmsvc/getallvms | grep -i your_vm_name | cut -d ' ' -f 1 | xargs vim-cmd vmsvc/get.guest | grep ipAddress | sed -n 1p | cut -d '"' -f 2
# or
ssh esxi.example.com /bin/vim-cmd vmsvc/get.guest $(ssh esxi.example.com /bin/vim-cmd vmsvc/getallvms | grep -i hostname | cut -d ' ' -f 1) | grep ipAddress | sed -n 1p | cut -d '"' -f 2
#or
vim-cmd vmsvc/get.guest your_vmid |grep -m 1 "ipAddress = \""
-
update network configuration of ESXi vms by command line
Gist file : updateNetworks.sh
options | commands |
---|---|
Register a VM | vim-cmd solo/registervm path_to_vmx_file |
Unregister a VM | vim-cmd vmsvc/unregister vmid |
Delete a VM | vim-cmd vmsvc/destroy vmid |
Get a listing of VMs on a host |
esxcli vm process list or vim-cmd vmsvc/getallvms
|
Determine if a VM has a snapshot | vim-cmd vmsvc/get.snapshot vmid |
Take a snapshot of a VM | vim-cmd vmsvc/snapshot.create vmid snapshot_name |
Remove a snapshot of a VM | vim-cmd vmsvc/snapshot.remove vmid |
Get the current power state of a VM | vim-cmd vmsvc/power.getstate vmid |
Get the uptime for a VM | vim-cmd vmsvc/get.summary vmid | grep uptimeSeconds |
Power on a VM | vim-cmd vim-cmd vmsvc/power.on vmid |
Shutdown a VM | vim-cmd vmsvc/power.shutdown vmid |
Power off a VM | esxcli vm process kill –w world_idvim-cmd vmsvc/power.off vmid |
Reboot a VM | vim-cmd vmsvc/power.reboot vmid |
Reset a VM | vim-cmd vmsvc/power.reset vmid |
Upgrade VMware Tools in a VM | vim-cmd vmsvc/tools.upgrade vmid |
Display the IP address of a VM | vim-cmd vmsvc/get.guest vmid |grep -m 1 "ipAddress = \"" |
查看Esxi版本 | vmware -v |
显示所有ESX相关信息 | esxcfg-info -a |
显示esx上硬件信息 | esxcfg-info -w |
重新启动vmware服务 | service mgmt-vmware restart |
查看宿主机IP地址 | esxcfg-vmknic -l |
cpu信息 Brand,Core Speed | esxcli hardware cpu list |
cpu信息 (CPU Cores | esxcli hardware cpu global get |
Physical Memory | esxcli hardware memory get |
硬件型号,供应商等信息,主机型号,Product Name 供应商,Vendor Name | esxcli hardware platform get |
当前时间 | esxcli hardware clock get |
查看ESXi主机版本号和build号 | esxcli system version get |
将ESXi主机进入到维护模式 | esxcli system maintenanceMode set -- enable yes |
将ESXi主机退出维护模式 | esxcli system maintenanceMode set --enable no |
列出ESXi主机上被改动过的高级设定选项 | esxcli system settings advanced list -d |
列出ESXi主机上被变动过的kernel设定部分 | esxcli system settings kernel list -d |
列出、测试和更改SNMP设定 | esxcli system snmp get | hash |set|test |
|
esxcli vm process list
# 利用esxcli列出ESXi服务器上VMs的World I(运行状态的)
esxcli vm process
kill
-t soft -w WorldI
# 利用esxcli命令杀掉VM
vim-cmd hostsvc``/hostsummary
# 查看宿主机摘要信息
vim-cmd vmsvc``/get``.datastores
# 查看宿主存储空间信息
vim-cmd vmsvc``/getallvms
# 列出所有虚拟机
vim-cmd vmsvc``/power``.getstate VMI
# 查看指定VMI虚拟状态
vim-cmd vmsvc``/power``.``shutdown
VMI
# 关闭虚拟机
vim-cmd vmsvc``/power``.off VMI
# 如果虚拟机没有关闭,使用poweroff命令
vim-cmd vmsvc``/get``.config VMI
# 查看虚拟机配置信息
esxcli software vib
install
-d
/vmfs/volumes/datastore/patches/xxx``.zip
# 为ESXi主机安装更新补丁和驱动
esxcli network nic list
# 列出当前ESXi主机上所有NICs的状态
esxcli network vm list
# 列出虚拟机的网路信息
esxcli storage nmp device list
# 理出当前NMP管理下的设备satp和psp信息
esxcli storage core device vaai status get
# 列出注册到PS设备的VI状态
esxcli storage nmp satp
set
--default-psp VMW_PSP_RR --satp xxxx
# 利用esxcli命令将缺省psp改成Round Robin
esxcli信息查询
-
esxcli命令帮助信息
ssh登录VMware ESX server控制台,用esxcli命令查询虚拟机信息,输出格式支持普通、xml、csv、keyvalue。
esxcli是一python编写的工具(/sbin/esxcli.py)。
使用--formatter=xml选项使结果以xml格式输出,更便于程序解析
通过ESXTOP中的k命令关闭虚拟机:
1. ssh登陆到ESXi主机,运行esxtop
2. 按c键切换到cpu模式
3. 按Shift+v,当前页面只显示虚拟机进程
4. 在当前显示中添加Leader World I这一列,找到要关闭的虚拟机的Leader World I
5. 按k键,在提示符模式下输入要关闭虚拟机的Leader World I,回车。
- 硬盘卷信息
df -h
#查看系统磁盘卷容量
- 查看网络信息
esxcli network ip interface ipv4 get
- 查看网络接口
esxcli network nic list
- 查看vswitch接口信息
esxcli network vswitch standard list