I create a simple PowerCLI script that backups all the ESXi hosts configurations that are connected in a vCenter server and displays the backup status in vCenter. To display the backup status in vCenter I created a global custom attribute called “Last ESXi Backup”.
After the ESXi PowerCLI backup script runs the “Last ESXi backup” field is updated with the current date.When the script is started the map that stores the ESXi configuration files is copied to an old map.
Here is an example how it looks in VMware Web Client:
And an example how it looks in the vSphere Client:
The script can be scheduled to make for example every week a backup of the ESXi server configs. You can easily customize the script for your own needs.
PowerCLI Script:
<# .SYNOPSIS Backup ESXi configration .VERSION 1.0 .DESCRIPTION Backups the configuration of all the ESXi servers .NOTES Author(s): Ivo Beerens Create a global custom field called "Last ESXi Backup" on the vCenter server .EXAMPLE ./BackupESXi.ps1 .Changes #>
#Load PowerCLI
Add-PSSnapin vmware.VimAutomation.core -ErrorAction SilentlyContinue
#Variables
$Folder = “E:\Backup\ESXi”
$FolderOld = “E:\Backup\ESXi\Old”
$Date = Get-Date -f dd-MM-yyy
# Connect to local vCenter Server
Connect-ViServer localhost
# Move existing backup files to the old directory
mv ($Folder + "\*.tgz") $FolderOld -force -ErrorAction SilentlyContinue
# Backkup ESXi configuration
Get-VMHost | Foreach {
$_ | get-vmhostfirmware -BackupConfiguration -DestinationPath $folder
$_ | Set-CustomField -name "Last ESXi Backup" -value "$Date"
}
# Disconnect session vCenter
Disconnect-VIserver -Confirm:$false
Had to omit the semi-colon “;” in line 28 after “.tgz” otherwise script works great!
Removed the semi-colon.Thanks Bryan for the feedback.
Will this script work with VCenter 5.5? i’m getting a bunch of errors when running for PowerCLI 5.5
I get errors stating “The term ‘Set-Customfield’ is not recognized as the name of a cmdlet etc etc