This week we need to PoweredOff all our VMs in our VMware Infrastructure, because of a Network Maintenance. The problem Powering off 2000 VMs is the Powering ON them back an. You need to track which ones were PoweredOn when you need to PowerOn them again, and with big Infrastructures, this can be tricky.

So I decided to create a PowerCli script that will create a List of all VMs that are in PoweredOn state before I PoweredOff the VMs.

UPDATED 06/07/2017: First script was updated with the option to Power off the VMs that are Power On (also check the VMware Tools state so that can do a hard power off, or a gracefully Power off. Depending if VMware Tools is running or not in the VM.

This update will create two files. One with all the records (power on, power off, VMware Tools running, not running and the number of VMs power off), and the second one with all VMs that was Power On so that we can use it in the second script to Power on them again.

First, let us create the VMs PoweredOn List. This script will create a simple text file with only the Virtual Machine name for future use/import.

Just run the script and will create a file (in the path you choose) called PowerOnVMs.txt

This is an output example of the file:

Now we have a list of all VMs that have the power on state. After we power off all the VMs that we need.

When we need to Power ON the VMs back again, we just run the second script to import all VM from the file created in the initial script.

This is an example of the file output:

The script will run trough all VMs list and will PowerON all the VMs that are inside that file.

Will also provide the Total number of VMs that were PowerOff and did not touch, and the number of VMs that did PowerON and will also create a file called PowerOffVMs.txt so that you have the record of all VMs that were PowerON and the ones that the script did not touch.

Hope these scripts help you.

Note: Share this article, if you think it is worth sharing.

©2017 ProVirtualzone. All Rights Reserved