|

Code Snips – Holodeck vApp Start Order

When deploying Holodeck, I like to add the VMs to a vApp so I can power-up/power-down the environment from one place. Because this is running vSAN, we want all the nodes to power up simultaneously to minimise any potential issues with the vSAN consistency.
When we create a vApp, the VMs will just get added to individual groups and start up sequentially.

This code snip will set every Holodeck VM in the vApp to Group 1, and also change the shutdown policy to “Guest Shutdown” instead of the default “Power Off”.

# Script to set all VMs in the vApp to Group1 / Shutdown Settings

Import-Module VMware.PowerCLI

# Set vApp Name
$vAppName = "HOLO-A-5.2.1"

# Set Host vCenter
$vCenter = "vcenter.lab.home"

Connect-VIServer $vCenter

# Set All VMs to Group 1 / Shutdown / Timeout / Waiting etc.
$vApp = Get-VApp -Name $vAppName
$spec = New-Object VMware.Vim.VAppConfigSpec
$spec.EntityConfig = $vApp.ExtensionData.VAppConfig.EntityConfig

foreach($key in $spec.EntityConfig){

    $spec.EntityConfig |  %{

        $_.StartOrder = "1"
        $_.WaitingForGuest = "True"
        $_.StopAction = "guestShutdown"
        $_.StopDelay = "360"

    }

}

# Apply Settings
$vapp.ExtensionData.UpdateVAppConfig($spec)

Disconnect-VIServer $vCenter -Confirm:$false

Similar Posts