Virtual Kim

@Kim_Bottu … Virtually Gung Ho

PowerCLI backup and restore an array of ESXi hosts

The following script makes a backup of the ESXi Host configuration file for an Array of Hosts in a folder on your Management station in C:\BackupMeUp. If you run the backup task multiple times, it will overwrite the saved configuration files for the hosts it already contains a configuration file for.

Backup an Array of ESXi hosts

Write-Host “Backing up ESXi config to C:\BackupMeUp”

$vmhost_array = @(“esxi1.mydomain.com”)
foreach ($vmhost in $vmhost_array) {
Get-VMHostFirmware -VMHost $vmhost -BackupConfiguration -DestinationPath C:\BackupMeUp
}

Write-Host “Backup is completed!”

The following script restores the host configuration from the folder on your Management station C:\BackupMeUp for an Array of Hosts. Make sure that you know which hosts it will restore, and that you modify this in the script. Not doing this will result in all the hosts reading and uploading the saved configuration file from C:\BackupMeUp, putting the hosts in maintenance mode and rebooting them!

Restore an Array of ESXi hosts

Write-Host

Write-Host “ESXi restore config from C:\BackupMeUp”

$vmhost_array = @(“esxi1.mydomain.com”)
foreach ($vmhost in $vmhost_array) {
Set-VMHost -VMHost $vmhost -State ‘Maintenance’
Get-VMHost -Name $vmhost | Set-VMHostFirmware -Restore -SourcePath c:\BackupMeUp-HostUser root -HostPassword password123

}

Write-Host “ESXi will REBOOT now”

Write-Host “Process complete”

For more information look here: https://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/Set-VMHostFirmware.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on March 11, 2015 by in Backup, ESXI, PowerCLI, Restore, Script and tagged , , , , .
Follow Virtual Kim on WordPress.com

Blog Stats

  • 26,240 hits
%d bloggers like this: