Thursday, 12 May 2016

How to Schedule reboot of ESXi Host

Let’s see how you can schedule a reboot of ESXi host using PowerCLI.

Make sure you have Windows System with PowerShell and PowerCLI installed on it.

First Add VMs in ESXi Virtual Machine startup/Shutdown configuration. During Power on or reboot of ESXi, these VMs will be auto started.


Schedule Below PowerCLI script to reboot esxi Host.

#Connect to ESXi Host

Connect-VIServer vlab-esxi2 -Username root -Password "password"

#Get All Powered On VMs on ESXi Host and Shutdown it. VMware Tools should be running in ESXi Host.

$vms = get-vm | where { $_.PowerState -eq "PoweredOn" }

#Shutdown, Powered on VMs

foreach ( $vm in $vms ) {Shutdown-VMGuest -VM $vm -Confirm:$false }

#Wait for 60 seconds So that all VMs shutdown process gets completed, you can increase wait time if you have more number of VMs.

sleep 60

#Restart ESXi Host

Restart-VMHost -Force -Confirm:$false


Save this script in file with c:\temp\RebootESXiHost.ps1

Schedule this script using Windows Task Scheduler to execute at specific time.

See How to schedule PowerCLI script using Windows Task Scheduler

if you want to Shutdown ESXi Host you can replace Restart-VMHost with Stop-VMHost command.

Good Luck….!



No comments:

Post a Comment