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.
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.
After you provided all the information, the scripts starts to backup the ESXi hosts and places the files into your desired location.
The script shows a progress bar while backing up the ESXi host.
After the backup is successful, your screen should look like this:
You can check your path where you wanted to place your backups if the ESXi host backup bundles appear:
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
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
Thanks for sharing.
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 ๐
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
Is this all Compatible with vSphere 7.x?
Hi Greg,
yes it should, I tried it with vSphere 7 and it worked fine.
Thanks !
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 !