vApp Script Extracts and Examples
Jump to navigation
Jump to search
Set VM Start/Stop Options
The following script sets all virtual machines within a vApp to have the same Start and Stop options (personally I don't like the default "power off" setting for VM's, I don't understand why you'd do this when the more graceful guest shutdown is available).
<# ========================================================================================================================================
vApp VM Start / Stop method updater
=========================================================================================================================================
Simon Strutt Jan 2011
=========================================================================================================================================
Used to give all VM's within a vApp the same start and stop methods
Version 1
- Initial creation
========================================================================================================================================#>
$vAppName = "YourvAppName"
$StartDelay = 120
$StartVMToolsReady = $true
$StopDelay = 120
$StopMethod = "guestShutdown"
#$StopMethod = "powerOff"
#$StopMethod = "suspend"
#$StopMethod = "none"
# Get view of vApp
$vAppView = Get-View (Get-vApp $vAppName)
# Prep reconfig object
$vAppConfigSpec = New-Object VMware.Vim.VAppConfigSpec
$vAppConfigSpec.entityConfig = New-Object VMware.Vim.VAppEntityConfigInfo[] ($vAppView.vAppConfig.EntityConfig.Count)
# Go through each child and check config is as we wish
$i = 0
foreach ($vm in $vAppView.vAppConfig.EntityConfig) {
$vAppConfigSpec.entityConfig[$i] = New-Object VMware.Vim.VAppEntityConfigInfo
$vAppConfigSpec.entityConfig[$i].key = $vm.Key
$vAppConfigSpec.entityConfig[$i].tag = $vm.Tag
$vAppConfigSpec.entityConfig[$i].startDelay = $StartDelay
$vAppConfigSpec.entityConfig[$i].waitingForGuest = $true
$vAppConfigSpec.entityConfig[$i].stopDelay = $StopDelay
$vAppConfigSpec.entityConfig[$i].stopAction = $StopMethod
$i ++
}
$vAppView.UpdateVAppConfig($vAppConfigSpec)