Updating your Image Profile

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

image

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

3 thoughts on “Updating your Image Profile

  1. Pingback: Auto Deploy: create updated HP ESXi image profile

  2. Christian Kotte

    Nice script, but we need some more logic when selecting the newest image. “Select-First 1” always selects my profile.

    If you are sorting for the Name then the order is also not correct.

    Get-EsxImageProfile -Vendor “VMware, Inc.” | Sort ModifiedTime -Descending | Where { $_.Name -notlike “*tools” } | Sort Name | ft -AutoSize

    Name Vendor Last Modified Acceptance Level
    —- —— ————- —————-
    ESXi-5.0.0-20110904001-standard VMware, Inc. 8/26/2011 1:41:00 PM PartnerSupported
    ESXi-5.0.0-20111104001-standard VMware, Inc. 10/13/2011 3:02:00 PM PartnerSupported
    ESXi-5.0.0-20111204001-standard VMware, Inc. 10/31/2011 11:24:00 AM PartnerSupported
    ESXi-5.0.0-469512-standard VMware, Inc. 8/19/2011 1:31:05 AM PartnerSupported
    ESXi-5.0.0-504890-standard VMware, Inc. 11/18/2011 1:59:38 PM PartnerSupported

    ESXi-5.0.0-504890-standard is btw my test image..

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.