2

I'm automating VM creation using VBoxManage unattended install and want to run script after installing which led me to --post-install-command option. The problem here is: the next steps in my script require Guest Additions, so I used --install-additions option in installation. Unfortunately, this option doesn't restart the machine after installing the Guest Additions, So I'm looking for a workaround so I restart the VM(from host or guest) and then continue my main script.

1 Answers1

1

Unfortunately, I didn't find any event triggered by VBox on VM boot up, so I had to wait for it to fully boot up.

It takes an average of 2-3 mins to fully boot up, so I used a timer of 3 mins.

$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