Monday, September 2, 2013

Gracefully shutdown VM using PowerCLI

This is very useful for me when I need to power off my lab at home (trying to conserver energy) :)

Prerequisites for this to work is that you have PowerCLI installed on your computer as well as vm tools installed on all vm's that you would like to utilize this on

Power off single machine:

get-vm vm-name | ShutdownVMGuest

Power off group of machines:

Create a text file with list of vm's you would like to shut down with each vm in separate line such as
Let say this file is called servers.txt and is located in c:\users\mike\desktop
First we will create variable to load servers from text files:
$servers = Get-Content -Path c:\users\mike\desktop\servers.txt
second we will use previous command to shut down group of servers in the file:
get-vm $servers | Shutdown-VMGuest

Turn on group of machines: (This please be careful with as if you try to turn on too many machines at one time you could potentially overload your ESX box)

Start-VM -VM $servers

No comments:

Post a Comment