VMware Cloud Community
tim5700
Contributor
Contributor
Jump to solution

Script to shutdown VMs.

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.

0 Kudos
1 Solution

Accepted Solutions
halr9000
Commander
Commander
Jump to solution

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

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000

View solution in original post

0 Kudos
3 Replies
halr9000
Commander
Commander
Jump to solution

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

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
tim5700
Contributor
Contributor
Jump to solution

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

0 Kudos
halr9000
Commander
Commander
Jump to solution

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

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos