How to backup ESXi hosts with PowerCLI

At the moment I have a lot of scripts laying around which are either snippets or not publishable. Therefore, I’m going to edit them all in the upcoming blog posts and upload them for the community. Today, I’m going to show you a simple but powerful and easy to use script to backup ESXi hosts configuration. This script is intended to use if you are planning on doing major changes to your ESXi hosts. The command I’m using is “Get-VMHostFirmware”. This command retrieves firmware information for the hosts which you want to back up.

I have put this all together in a simple script which asks you for your vCenter server, credentials and the path where you want to store your backups.

How to backup ESXi hosts with PowerCLI

Simply execute the script and follow the steps to fill in the relevant data like an IP address, the username, your password and your destination path in which you want to save the backup files.

Executing PowerCLI script

After executing the script you will need to fill out the necessary information to connect to the vCenter Server and therefore to backup th ESXi host configuration.

Filled out script

After you provided all the information, the scripts starts to backup the ESXi hosts and places the files into your desired location.

backup ESXi hosts

The script shows a progress bar while backing up the ESXi host.

After the backup is successful, your screen should look like this:

backup ESXi hosts

You can check your path where you wanted to place your backups if the ESXi host backup bundles appear:

check for files

I hope this is a handy tool for you and helps you with your host backup. Feel free to provide me some feedback!

You can get the script on my github page: https://github.com/falkobanaszak/backup-esxi-host-configuration

In addition, feel free to check my github page in general, as I have some more scripts uploaded there: https://github.com/falkobanaszak

About Falko Banaszak

Falko is a consultant based in Germany working for SVA GmbH. He has a strong focus on virtualization, data backup, disaster recovery infrastructures and a passion for Microsoft 365 & storage systems. He´s a VMware vExpert & Veeam user group leader in Germany. VCP-DCV, VMCE, VMCA.

Check Also

VMware PowerCLI logo

Get vSphere Tags out of a category with PowerCLI

Introduction to vSphere Tags Using vSphere tags in your VMware environment is no longer a …

5 comments

  1. Is there a way to restore these backups?

    • Hi Steve,

      yes you can restore these backups.
      The ESXi host should be placed into maintenance mode first. After that, you can restore the host configuration with the “Set-VMHostFirmware” cmdlet.
      Here is an example:

      Set-VMHostFirmware -VMHost esxhost.yourdomain.com -Restore -Force -SourcePath C:\temp\configBundle-esxhost.yourdomain.com.tgz
      In addition, here is the reference page of this cmdlet: Set-VMHostFirmware – PowerCLI Reference
      Hope this helps !

      Best Regards

      Falko

  2. Hi,

    I get a heap of PS errors when running the script. What modules does it require? The errors are as follows:

    PS C:\users\temp\desktop> .\Backup_ESXi_Host_Configuration.ps1
    Enter vCenter Server host name (DNS with FQDN or IP address): 192.168.8.8
    Enter your user name (DOMAIN\User or user@domain.com): root
    Enter your password (no worries it is a secure string): ********
    Enter the path where you wish to store the backup file: c:\
    Connect-VIServer : 6/03/2020 2:05:26 PM Connect-VIServer Error: Invalid server certificate. Use
    Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you’d like to connect
    once or to add a permanent exception for this server.
    Additional Information: Could not establish trust relationship for the SSL/TLS secure channel with authority
    ‘192.168.8.8’.
    At C:\users\vlado\desktop\Backup_ESXi_Host_Configuration.ps1:59 char:1
    + Connect-VIServer -Server $vCenterServer -Credential $Credentials
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
    Cmdlets.Commands.ConnectVIServer

    Connected to your vCenter server 192.168.8.8
    Get-VMHost : 6/03/2020 2:05:26 PM Get-VMHost You are not currently connected to any servers. Please connect first
    using a Connect cmdlet.
    At C:\users\vlado\desktop\Backup_ESXi_Host_Configuration.ps1:63 char:1
    + Get-VMHost | Get-VMHostFirmware -BackupConfiguration -DestinationPath …
    + ~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [Get-VMHost], ViServerConnectionException
    + FullyQualifiedErrorId : Core_BaseCmdlet_NotConnectedError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

    Successfully backed up the configuration of the host of 192.168.8.8 to c:\
    Disconnect-VIServer : 6/03/2020 2:05:26 PM Disconnect-VIServer PowerCLI is currently not connected to a server. To
    create a new connection use Connect-VIServer.
    At C:\users\vlado\desktop\Backup_ESXi_Host_Configuration.ps1:67 char:1
    + Disconnect-VIServer -Confirm:$false
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Disconnect-VIServer], ViServerConnectionException
    + FullyQualifiedErrorId : Core_DisconnectVIServer_NotConnectedError,VMware.VimAutomation.ViCore.Cmdlets.Commands.D
    isconnectVIServer

    Disconnected from your vCenter Server 192.168.8.8 – have a great day 🙂

    • Falko Banaszak

      Hi Vlado,
      I updated the script so it ignores the certificate.
      If you try again with the new version on github it should work !

      Best Regards
      Falko

Leave a Reply

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