Using Windows task scheduler you can schedule power off and on events for guest systems running in VMware vCenter or a standalone ESXi host.
- Create a basic task – give it a name and description (optional)
- Choose when you want this task to stat
- Select the start date and time
- Choose “Start a program”
- Choose the program you would like to run. In this setup we will be running the following:
- C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -File “C:\work\task\jermsmit.ps1”
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -File "C:\work\task\jermsmit.ps1"
- Click Next, Select Yes when Task Scheduler prompts you
- On the Finish screen, click Finish – You can open properties to set this to run unattended
The script I am now using does the following:
- Loads the VMware PowerCli modules to powershell
- Connects to Specified ESXi or vCenter Server
- Issues a stop to specific VM Guests
- Issues a start to the VM Guest
# 2015-04-22 # Power Off, Power On Powershell/PowerCli Script # By: jermsmit - @jermsmit # Add all installed VMware cmdlests Add-PSSnapin Vmware* # Connects to Specified ESXi Server Host Connect-VIServer -Server 10.255.12.6 -User root -Password adfdssssf! # Issue Stop to Virtual Machine Guest # Example Forceful Stop: Stop-VM -VM "web" -Kill -Confirm:$false Stop-VM -VM "torproxy" -Confirm:$false Stop-VM -VM "minecraft-vanilla" -Confirm:$false Stop-VM -VM "web" -Confirm:$false # Sleeps for 60 Seconds Start-Sleep -Seconds 60 # Issue Start to Virtual Machine Guest Start-VM -VM "torproxy" -Confirm:$false Start-VM -VM "minecraft-vanilla" -Confirm:$false Start-VM -VM "web" -Confirm:$false
- Powering systems down to conserve energy (earth day initiative)
- Allow for systems with large workloads to have full system resources without contention during scheduled down periods of the systems that are offline.
- Quick restore of nonpersistant environments
Thanks for visiting – jermal
5 replies on “Power Off & On VMware Guest with a Scheduled Task”
Many thanks Jermal.
I have been hunting high and low for some info like this. I have trawled the VMWare site and many many forums but none of them had any info that would help me write a script to shutdown our VM’s gracefully and in a set order. But what was even more beneficial to me, was the simplicity of your script. We have 3 hosts and 30 guests in our HA cluster and many of the VM’s are web and SQL servers, which need to be restarted in a specific order. Your script gave me the basis of what I have now tested and proved to be just what we needed to manage the shutdowns when our mains power fails and the batteries in the UPS reach our maximum shutdown threshold.
Andy, thank you for the comment. Yes this is a ‘simple’ script to do a specific task. I’ve haven’t had a need to go back and modify it and it works for a demo environment flawlessly.
If you care to share what your script, and how your using it, I’m sure it will go a long way in helping others; including myself develop new methods.
This worked out perfect!! Thanks!
Thanks for the post this helped us…Do you also have the similar scripts for the following steps: “shutting down” the VM and “delete it from the disk” and “clone to virtual machine” by specifying the VM name, selecting the host, selecting the virtual disk format and Finish.
I hope that is not your password bud.