Dec 222010
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 $VAppView.UpdateVAppConfig($VAppConfigSpec) } } } Disconnect-VIServer -Confirm:$false
Download script: Set-VAppGuestShutdown (rename to .ps1)
Related posts:

Thanks,
Works perfect.
This works perfectly. One question, if I wanted to set the StopAction, or in mycase StartAction for a particular VM in a VApp, how would I go about it. I can see how you set them all, just can’t see how to select a specific VM in the VApp. Thanks
Robin,
The easiest way is like this (note the “myVMName”). If you are using it in a larger script you can reference the vm’s by MoRef, but I will skip that explanation for now.
Hugo
Just got bit by this! Thanks for the script!