Easy PowerShell script to backup ESXi configs

Associate
Joined
1 Dec 2005
Posts
803
I spent a little time today checking this item of my todo list. This script is based on some of the code from here but simplified so that it can run as a Scheduled Task.

Code:
Add-PSSnapin VMware.Vimautomation.Core -ea SilentlyContinue

#$user=""
#$pass=""
$vCenterServer="lynx.ad.niknak.org"
$SaveLocation="C:\vSphere Backups\"

Connect-VIServer -server $vCenterServer -ErrorAction Stop #-user $user -password $pass 

$VMHosts = Get-VMHost | Where { (($_.ConnectionState -eq "connected") -or ($_.ConnectionState -eq "Maintenance")) }
foreach ($VMHost in $VMHosts) 
{
	Get-VMHostFirmware -VMHost $VMHost -BackupConfiguration -DestinationPath $SaveLocation -ErrorAction:SilentlyContinue
}

Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false
Copy the above and save somewhere as a .ps1 file. Substitute your values for the variables at the top as appropriate. Uncomment the authentication bits if you don't want to connect as the current user (or the user running the Scheduled Task). If you only have a single ESXi host or aren't using vCenter then you can simplify things further and only run the Get-VMHostFirmware line with a specific -VMHost value specified, instead of looping over hosts found in vCenter.

Hopefully that's useful for others :)
 
Thanks for sharing.

You can use Get-VICredentialStoreItem to prevent storing the password in plain text. Something like:

$creds = Get-VICredentialStoreItem -file "\\fileserver\ITSecure\vcentercreds.xml"

Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password
 
+1 thanks.

What i do as well, backup configurations for servers/settings also go dropbox (shared among a few in the department)

So if anything happened to the san , we got it the info.
 
Back
Top Bottom