Set vApp Guest Shutdown

Annoyed by the default setting for VM’s inside a vApp? I was, because when you power down the vApp, the VM’s are powered down instead of being shutdown cleanly. It can be a tedious task to check and correct this setting for all your vApps. This little script solves that problem for you. Enjoy!

$VC = Connect-VIServer "MyvCenter.local"
ForEach ($Vapp in Get-VApp)
	$VAppView = $VApp | Get-View
	ForEach ($Entity in $VAppView.VAppConfig.EntityConfig)
		If ($Entity.StopAction -ne "guestShutdown")
		$VAppConfigSpec = New-Object VMware.Vim.VAppConfigSpec
		$EntityConfig = New-Object VMware.Vim.VAppEntityConfigInfo
			$EntityConfig.Key = (Get-View $Entity.Key).MoRef
			$EntityConfig.StopAction = "guestShutdown"
		$VAppConfigSpec.EntityConfig = $EntityConfig
Disconnect-VIServer -Confirm:$false

Download script: Set-VAppGuestShutdown (rename to .ps1)