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