Recently I’ve found myself having to shutdown my home lab quite often as the weather has been better than expected and the temperature has risen dramatically. Great for sitting in beer gardens, not so good for the lab.
To speed up the process of shutting down all my VMs (currently 68 of them) I decided to knock up a very simple PowerCLI script:
# Variables $esxi = "esxi.mdb-lab.com" $credential = Get-Credential Connect-VIServer $esxi -Credential $credential Get-VM | where {$_.Powerstate -eq "PoweredOn"} | Shutdown-VMGuest -Confirm:$false Start-Sleep -s 600 Stop-VMHost -Confirm:$false -Force:$true Disconnect-VIserver $esxi -Confirm:$false
Definitely not rocket science, but the greatest scripts don’t always have to be complicated.
There are a lot of other devices (storage and networking equipment) that also have to be scripted to shutdown, but this is a start.