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 Consulting Field Solutions Architect for Modern Data Protection based in Germany working at Pure Storage Inc. In the last 12 years he has built a strong focus on virtualization, BCDR and has a passion for Microsoft 365 & storage systems. He's a Veeam Vanguard, a Veeam Certified Engineer, Veeam Certified Architect and a Veeam User Group founder and leader in Germany.

Check Also

VeeamON 2022

VeeamON 2022 – in person or virtual

By far the best data protection event VeeamON 2022 – in person or virtual is …

9 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

  3. Is this all Compatible with vSphere 7.x?

  4. Hi,

    I get a heap of PS errors when running the script. What resolution for this? The errors are as follows:

    Set-PowerCLIConfiguration : The term ‘Set-PowerCLIConfiguration’ is not recognized as the name of a cmdlet, function,
    script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    At C:\backup-esxi-host-configuration-master\Backup_ESXi_Host_Configuration.ps1:39 char:1
    + Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$ …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Set-PowerCLIConfiguration:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Enter vCenter Server host name (DNS with FQDN or IP address):

    • Hi Jiang,
      from the errors you posted it seems like you do not have the VMware PowerCLI Module installed.
      The script itself should be performed within a VMware PowerCLI or a PowerShell with the module installed.
      Let me know how it goes
      Thanks !

Leave a Reply

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