Pages

Tuesday, January 7, 2014

Script to backup ESXi configurations for all hosts in the cluster





This script is used to backup the ESXi configuration of all the hosts in the cluster. This backup will serve in the event if a VMware host has to be rebuild and if the configuration of a host goes corrupt  or compromised.This is a powershell script that requires the vmware powercli module.






#This script will backup the hosts Configuration


#Created By: Ruby Nahal

#run as scheduled task using the a service account that has 
#administrative rights on vcente. vcenter must have powercli installed

#this script creates the backup in D:\esxibackups and each backup is replaced # by the new one

# it also copies the backups to \\fileserver\share\backups



#Load the vmware powershell snapin

add-pssnapin vmware.vimautomation.core



#Connect to the vCenter Server

Connect-VIServer vcenter-01



#grab the list of hostnames

$esxihosts = get-VMhost | select name



#Print the list

Write-Output $esxihosts



#variable of type string to convert the object $esxihost to string value

[string]$esxihostname

Foreach ($esxihost in $esxihosts)

                {

                $esxihostname = $esxihost.Name

                Write-Output $esxihostname

                Get-VMHostFirmware -VMHost $esxihostname -BackupConfiguration -DestinationPath D:\esxibackups

                }

Copy-Item -Path D:\esxibackups -Destination \\fileserver\share\backups -Recurse -Force

No comments:

Post a Comment