If you have been using the image builder and auto deploy cmdlets which came with vSphere 5.0 then you will already know how easy it is to completely rebuild all hosts just by replacing a simple auto deploy rule with your new image profile and then rebooting your hosts.
But how do you create your new image profile ?
An Image profile normally consists of a base ESXi image downloaded from VMware and then some custom software packages added in to ensure you have all the third party addons, drivers and utilities needed for the host to work with your infrastructure.
An example of this is the EMC PowerPath Software Package or the HP ESXi Proliant offline bundle, others may include the software package needed for the vCD Agent.
Once these software packages have been added to your image profile you are then able to export it back as an offline zip file, ISO file or use it in you Auto Deploy rule-set.
But when it comes to updating you need to remember which software packages you added to which build of ESX and repeat this procedure, this can be time consuming.
Introducing Update-ESXImageProfile
Did you know that VMware has an online repository of up to date versions of ESXi Software Depots ? You can easily add this to your Image Builder session with the following line of code:
Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml

Using this online depot I was able to create a script which would download any newer software packages from the base ESXi Software Depot online and compare these against your current image profile, once this has been done it will add these latest versions to your image profile ensuring you have an up-to-date Image Profile.
Of course you will need to make sure you export this as a zip again so you can use it in the future and also add it to your Auto Deploy rule-set and reboot your hosts.
See it in action
The Script
Function Update-ESXImageProfile ($ImageProfile, $tools){
if ($ImageProfile.Readonly) {
Write-Host "Your ImageProfile is read-only and therefore cannot be updated, please use a custom ImageProfile"
} Else {
Write "Loading online Software Depot"
$SD = Add-EsxSoftwareDepot -DepotUrl https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
If ($tools) {
$NEWIP = Get-EsxImageProfile -Vendor "VMware, Inc." | Sort ModifiedTime -Descending | Where { $_.Name -notlike "*tools" } | Select -First 1
} Else {
$NEWIP = Get-EsxImageProfile -Vendor "VMware, Inc." | Sort ModifiedTime -Descending | Where { $_.Name -like "*tools" } | Select -First 1
}
Write-Host "New Image Profile found called $($NEWIP.Name)..."
Write-Host "Checking for updated packages which do not exist in $ImageProfile"
$Compare = Compare-EsxImageProfile -ReferenceProfile $ImageProfile -ComparisonProfile $NEWIP
$Updates = ($Compare | Select -ExpandProperty UpgradeFromRef)
If ($Updates) {
Foreach ($SP in $Updates) {
$UpdatedPackage = Get-EsxSoftwarePackage | Where {$_.Guid -eq $SP}
Write-Host "Adding $($UpdatedPackage.Name) to $ImageProfile"
$Add = Add-EsxSoftwarePackage -ImageProfile $ImageProfile -SoftwarePackage $UpdatedPackage
}
}
$OnlyInComp = ($Compare | Select -ExpandProperty OnlyInComp)
If ($OnlyInComp) {
Foreach ($SP in $OnlyInComp) {
$UpdatedPackage = Get-EsxSoftwarePackage | Where {$_.Guid -eq $SP}
Write-Host "Adding $($UpdatedPackage.Name) to $ImageProfile"
$Add = Add-EsxSoftwarePackage -ImageProfile $ImageProfile -SoftwarePackage $UpdatedPackage
}
}
If ((-not $OnlyInComp) -and (-not $Updates)) {
Write-Host "No Updates found for $ImageProfile"
}
}
}
Update-ESXImageProfile -ImageProfile "CustomImageProfile" -Tools $true