I’m a big fan of PowerCLI one-liners. 🙂
Before performing updates, upgrades or any other maintenance on ESXi hosts, you should backup your ESXi host configuration. Setting up a new ESXi host as replacement is a no-brainer, but rebuilding a lost configuration can be a PITA and might take hours.
In the old times it was necesary to open a SSH shell connection or to use vSphereCLI to issue backup commands to ESXi hosts. Recently I realized that there is a very handy PowerShell commandlet to backup and restore the configuration.
Backup
Connect-VIserver myvc.mydomain.com
Login as an administrator.
Get-VMhost | Get-VMHostFirmware -BackupConfiguration -DestinationPath "C:\temp"
Within seconds you’ll find host configurations of all ESXi registered to vCenter in c:\temp.
If you like to backup only a single hosts config, you need to modify the command a little.
Get-VMHostFirmware -VMHost myesx.mydomain.com -BackupConfiguration -DestinationPath "C:\temp"
Restore
Sometimes you need to restore the configuration. Maybe your ESXi host fails to boot after some maintenance, because the boot media is damaged. Replace the media, deploy a new ESXi, set a static IP address and restore the configuration.
Before restore your host must be in maintenance mode. To enter maintenance mode by PowerCLI issue the command below.
Set-VMHost -VMHost esx1.mydomain.com -State "Maintenance"
Now you can restore the configuration.
Set-VMHostFirmware -VMHost esx1.mydomain.com -Restore -Force -SourcePath c:\temp\configBundle-esx1.mydomain.com.tgz
One reboot and your host will be up and running again.
Links
vSphere PowerCLI Cmdlets Reference – Get-VMHostFirmware
vSphere PowerCLI Cmdlets Reference – Set-VMHostFirmware