Wednesday Tidbit: Shutdown your lab with one click

20150713 - PowerCLIRecently 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.