Auto ESXi Host Configuration Backups with PowerCLI

Regularly throughout the year, I like to take PIT (Point in Time) backups of my ESXi host configurations. These form part of my Critical Config backups that I hope I’ll never have to use.

But like any backup, these are merely another safety net as we strive to have more resilient systems.

With the calendar year now drawing to a close, it’s a good time to do this procedure.

PowerCLI makes this task simple and a non-event. This will utilize the “Get-VMHostFirmware” commandlet.

From a PowerCLI session, establish a connection to your VC server (or single ESXi host) using Connect-ViServer

Note: if you have the original self-signed certificate and receive yellow warning message regarding an invalid cert, you can run Set-PowerCLIConfiguration – InvalidCertifcateAction Ignore to ignore the warning.

The following one liner will backup the host with the esxihostname value and place the config bundle into C:\CriticalConfigs\ESXiHosts

Now let’s put this to work in a more useful way.

The following will backup all hosts connected to the Virtual Center server you specify, and save the config bundles to C:\CriticalConfigs\ESXiHosts. The backup files will have the current date (in the format specified in the $datetime variable appended to the default filename, before the extension.

After the files are renamed, an email is sent showing the filenames and locations for reference and verification.

Files already in the Output Directory will be moved to the Archive directory specified.

Configure the variables;

  • $savedir                   [Location for the config backup bundles]
  • $archivedir              [Location for backup archives]
  • $datetime                [Change the format as required, I have it set to ddMMYY]
  • $VCServer               [Change to your Virtual Center Server hostname]
  • Email details in the ‘EmailResults‘ Function will need to be customised for your own environment also.

Script execution;

30-12-2014 5-14-29 PM

 

 

 

 

 

 

 

 

 

 

 

 

Files after being processed;

30-12-2014 5-01-40 PM

 

 

 

 

 

Email Message body;

30-12-2014 6-29-55 PM

 

 

 

 

 

 

 

This is more of a modularised script, so more function blocks can be added in as required, or to form a larger base to do more tasks.

It’s easily customisable, for example if you wanted to restrict it to certain hosts, cluster(s) multiple VC servers, filter the “Get-VMHost” using ‘where’ options.

Add it into a scheduled task according to your preference or run it on demand.

Happy backups..

 

 

 

 

 

1 thought on “Auto ESXi Host Configuration Backups with PowerCLI

  1. Graham

    Hey Guys,

    Great Script, Thanks, but i have a few questions ?

    when i launch the script i have a few errors –
    Get-VMHostFirmware : 25/06/2018 15:55:46 Get-VMHostFirmware A general system error occurred: Internal error
    At Y:\Script Backup\Vmware-AutoConfigBackup.ps1:27 char:14
    + … et-VMHost | Get-VMHostFirmware -BackupConfiguration -DestinationPath …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-VMHostFirmware], SystemError
    + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_BackupVmHostFirmware_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostFir
    mware

    any Ideas what is going wrong ?

    Reply

Leave a Reply

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