PeetersOnline.nl
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 $VAppView.UpdateVAppConfig($VAppConfigSpec) } } } Disconnect-VIServer -Confirm:$false |
Download script: Set-VAppGuestShutdown (rename to .ps1)
4 Responses to Set vApp Guest Shutdown
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





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!