How to power on bulk VMs automatically in PowerCli

Here’s a script using PowerCLI to handle disaster recovery by powering on VMs while ensuring that VMs originally powered off remain off. The script includes functionality to back up the current power state of VMs, compare it with the stored power state, and display a progress bar during the recovery process.

What this script will do:
1) It will backup the current Power State of VMs to csv file. It will create the new csv file if not already created.
2) If the file is already created, it will check the current power state of VMs by comparing with the csv file.
3) If the Powered On server in the list is found as powered off in vCenter or esxi, it will power on all VMs.

Please note that you will need to connect the vCenter/Esxi before running the script. Also, you will need to disconnect the vCenter/Esxi connection once the job is finished.

Use the the following command to connect to the host.
Connect-VIServer -Server yourserver -Credential (get-credential)

Use the following command to disconnect from host.
Disconnect-VIServer -Server yourserver -confirm:$false

PowerCLI Saving VM Power State and Power On VMs
Fig-1: Demo of Saving VM Power State and Power On VMs

 

PowerCLI Powering on VM in action
Fig-2: Powering On VM in Action

You can download my script from the github.

Leave a Reply

Your email address will not be published. Required fields are marked *