I am in the process of configuring a powershell script to VIM 1.5. The goal of the script is to initiate a graceful shutdown for VMs when running on battery backup. I would like to be able to shutdown/start VMs based on what folder they are in under VMs & Templates in VC.
Basically, what I am looking for is when the script is triggered, a short delay (say 5 minutes), then all the VMs in folder "GroupC" shutdown, then 15 minutes the VMs in folder "GroupB" shutdown, then finally, after 25 minutes the VMs in folder "GroupA" shutdown.
An added bonus would to create a script to run when going back on power, to stop the shutdown script and start any VMs that were shutdown.
You got it.
[PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org
Easy, peasy.
Start-Sleep ( 60 * 5 )
Get-Folder foo | Get-VM | Stop-VM
[PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org
First, thanks for the fast response.
OK, so since I am doing a clean shutdown of the VMs I would do:
Get-Folder name "GroupC" | Get-VM | Shutdown-VMGuest ?
And then will that work for powering up as well?
Get-Folder name "GroupC" | Get-VM | Start-VM
You got it.
[PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org