Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Creates a ESXi Image from Online Depot and adds additional packages
# Load ImageBuilder Snapin (if not already loaded)
if (!(Get-PSSnapin -name VMware.ImageBuilder -ErrorAction:SilentlyContinue)) {
if (!(Add-PSSnapin -PassThru VMware.ImageBuilder)) {
# Error out if loading fails
write-host "`nFATAL ERROR: Cannot load the ImageBuilder Snapin. Is the PowerCLI installed?`n"
# Definde Global
$vmwdepotURL = ""
$BaseImageProfile = "ESXi-5.5.0-20150504001-standard"
$AddonsDir = "C:\ESXi-DL360\Addon\"
$OutDir = "C:\ESXi-DL360\"
$NewProfileName = "HP-55U2-20160209"
# Add Budles:
write-host "Adding Base Image from Online Depot..." -ForegroundColor DarkMagenta
write-host "**********************" -ForegroundColor DarkMagenta
write-host "Adding online Depot from $vmwdepotURL ..."
$basedepot = Add-EsxSoftwaredepot $vmwdepotURL
# Add Addons:
write-host "Adding Addons from Offline Depots..." -ForegroundColor DarkMagenta
write-host "************************************" -ForegroundColor DarkMagenta
foreach ($Bundle in Get-Item $AddonsDir\*.zip) {
write-host " Adding $Bundle ..."
write-host ""
Add-EsxSoftwareDepot $Bundle | Out-NUll
# Create ImageProfile:
write-host "Creating new Image Profile..." -ForegroundColor DarkMagenta
write-host "*****************************" -ForegroundColor DarkMagenta
$OldProfile = Get-EsxImageprofile $BaseImageProfile -Softwaredepot $basedepot
$NewProfile = New-EsxImageProfile -CloneProfile $BaseImageProfile -Name $NewProfileName -Vendor HP -AcceptanceLevel PartnerSupported
# Add Addon VIBs:
write-host "Adding Addon Packages..." -ForegroundColor DarkMagenta
write-host "************************" -ForegroundColor DarkMagenta
Get-EsxSoftwarePackage | where { $_.SourceUrls -Like "*$AddonsDir*" } | sort Name, Version | foreach {
write-host " Adding VIB" $_.Name $_.Version
Try {
Add-EsxSoftwarePackage -SoftwarePackage $_ -ImageProfile $NewProfile | Out-Null
Catch {
Switch -Wildcard ($_.Exception)
"*is already in ImageProfile*"
{Write-Host "...Is alredy in Profile" -ForegroundColor Yellow}
{ Write-Host $_.Exception -ForegroundColor Red}
# View Result:
write-host "VIB List in New Image Profile:" -ForegroundColor DarkMagenta
write-host "******************************" -ForegroundColor DarkMagenta
(Get-EsxImageProfile -Name $NewProfileName).VibList | Select Name, Version | Sort Name | ft -AutoSize
write-host "Exporting Image Profile..." -ForegroundColor DarkMagenta
write-host "********************************" -ForegroundColor DarkMagenta
$path = $OutDir + $NewProfileName + ".zip"
Export-EsxImageProfile -ImageProfile $NewProfileName -ExportTobundle $path | Out-Default
$path = $OutDir + $NewProfileName + ".iso"
Export-EsxImageProfile -ImageProfile $NewProfileName -ExportToIso $path | Out-Default
#Remove Bundles:
write-host "Unloading Depots..." -ForegroundColor DarkMagenta
write-host "*******************" -ForegroundColor DarkMagenta
Remove-EsxSoftwareDepot $DefaultSoftwareDepots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.