Friday, May 27, 2016

PowerCLI: Automatically Power on VMs from the Saved CSV file

It's the Powershell script using PowerCLI to power on a bunch of VMs when multiple servers go offline or during disaster recovery. Not using any third-party tools, I got the idea to do it in PowerCLI to backup the current Powerstate of the VMs to csv file and compare it when powering on VMs, so that you do not mistakenly turn on VMs that are initially powered off. I added the progress bar to get the progress state of powering on VMs.

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



1 comment:

  1. Techsaga, as Digital marketing company in Noida experts, deliver inspiring, eye-catching designs and measurable campaigns that connect with target audiences, boost online marketing and encourage business growth. We can help you meet your needs across a range of full service online marketing services. Are you looking for help with great content, SEO, PPC campaigns, a full digital marketing strategy, campaign, or something else? No matter what you need, our experts can help you.

    ReplyDelete

Note: Only a member of this blog may post a comment.