如何使用VirtualBox CLI重新启动VM并等待它再次完全启动?

如何使用VirtualBox CLI重新启动VM并等待它再次完全启动?,virtualbox,virtualbox-guest-additions,Virtualbox,Virtualbox Guest Additions,我正在使用VBoxManage无人参与安装自动创建虚拟机,并希望在安装后运行脚本,这导致我选择了--安装后命令选项。 这里的问题是:脚本中的下一步需要来宾添加,因此我在安装中使用了--install Additions选项。不幸的是,此选项在安装来宾添加后不会重新启动计算机,因此我正在寻找一种解决方法,以便重新启动VM(从主机或来宾),然后继续我的主脚本。不幸的是,我在VM启动时未找到任何由VBox触发的事件,因此我必须等待它完全启动 完全启动平均需要2-3分钟,所以我使用了3分钟的计时器 $p

我正在使用
VBoxManage无人参与安装
自动创建虚拟机,并希望在安装后运行脚本,这导致我选择了
--安装后命令
选项。
这里的问题是:脚本中的下一步需要来宾添加,因此我在安装中使用了
--install Additions
选项。不幸的是,此选项在安装来宾添加后不会重新启动计算机,因此我正在寻找一种解决方法,以便重新启动VM(从主机或来宾),然后继续我的主脚本。

不幸的是,我在VM启动时未找到任何由VBox触发的事件,因此我必须等待它完全启动

完全启动平均需要2-3分钟,所以我使用了3分钟的计时器

$postInstallCommands = 'VBoxControl guestproperty set installation_finished y && (shutdown /s || shutdown -P now)'

########## Initiate unattended installation
VBoxManage unattended install "$vmName"  `
    --iso="$isoFile"                         `
    --user="$userName"                       `
    --password="$password"                   `
    --full-user-name="$userName"             `
    --install-additions                      `
    --locale=en_US                           `
    --country=US                             `
    --time-zone=EST                          `
    --image-index=1                          `
    --post-install-command="$postInstallCommands" *> $null
    
########## Start VM and wait to finish install
VBoxManage startvm "$vmName" --type headless

Write-Host "Waiting for VM to finish OS installation..."
VBoxManage guestproperty wait "$vmName" installation_finished *> $null

Start-Sleep -s 180

你有没有想过如何重新启动虚拟机?甚至运行
--post install命令
,而不考虑重新启动?请检查此项