# 如果有虚拟机还在运行,则退出 for ID in $(vim-cmd vmsvc/getallvms | grep -vE '(iKuai|OpenWrt|Vmid)' | awk '{print $1}'); do if vim-cmd vmsvc/power.getstate ${ID} | grep -q "Powered on"; then echo"当前还有虚拟机在运行 ID: ${ID}" exit 0 fi done
# 否则关闭虚拟机 for ID in $(vim-cmd vmsvc/getallvms | grep -v 'Vmid' | awk '{print $1}'); do if vim-cmd vmsvc/power.getstate ${ID} | grep -q "Powered on"; then echo"关闭虚拟机 ID: ${ID}" if ! vim-cmd vmsvc/power.shutdown "${ID}"; then echo"强制关闭虚拟机 ID: ${ID}" vim-cmd vmsvc/power.off "${ID}" fi fi done
# 关闭ESXi echo"已关闭全部虚拟机,即将关机" esxcli system maintenanceMode set --enabletrue esxcli system shutdown poweroff --reason "no vm Runing!" --delay 300 esxcli system maintenanceMode set --enablefalse
# Note: modify at your own risk! If you do/use anything in this # script that is not part of a stable API (relying on files to be in # specific places, specific tools, specific output, etc) there is a # possibility you will end up with a broken system after patching or # upgrading. Changes are not supported unless under direction of # VMware support.
# Note: This script will not be run when UEFI secure boot is enabled.
XRSec has the right to modify and interpret this article. If you want to reprint or disseminate this article, you must ensure the integrity of this article, including all contents such as copyright notice. Without the permission of the author, the content of this article shall not be modified or increased or decreased arbitrarily, and it shall not be used for commercial purposes in any way