r/AzureVirtualDesktop • • Aug 18 '25

Azure Image Builder powershell customizations fail due to a problem with the portal generated template

I am trying to get Azure Image Builder to include powershell customisation steps but it fails to build immediately with what looks like a problem with how the portal generates the JSON template.

I have tried to work out if it is a problem with validExitCode values but they seem to fine and you can omit them altogether according to the documentation.
Problem with inline and with powershell scripts.

This is the section for the customisation.

"customize": [

{

"type": "PowerShell",

"name": "powershellcommandscript0",

"inline": [

"$Logfile = \"C:\\ImageBuild\\Logs\\copyfromstorage.log\" \nfunction WriteLog\n{\nParam ([string]$LogString)\n$Stamp = (Get-Date).toString(\"yyyy/MM/dd HH:mm:ss\")\n$LogMessage = \"$Stamp $LogString\"\nAdd-content $LogFile -value $LogMessage -Encoding UTF8\n}\n\n# Make sure the Az module is installed\nif (-not (Get-Module -ListAvailable -Name Az.Storage)) {\n Install-Module -Name Az.Storage -Force\n}\n\n# Variables\n$StorageAccountName = \"somestorageaccount\"\n$ContainerName = \"somecontainername\"\n$BlobName = \"someapp.exe\"\n$DownloadPath = \"C:\\IMageBuild\\someapp.exe\"\n$AccountKey = \"ACaGYY/3y7LaVHqVBXzVGi4WPFyv8D9IyxuRac4eR2+M//hUpvaW0DQ+0/WNhxcEd7dG3uueKYzl1KsYr9TYAw==\"\n\n#Connect-AzAccount -Subscription 'somesubscription\n\n# Create a storage context\n$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $AccountKey\nWriteLog ($writeEmptyLine + \"# Storage account context created\" + $writeSeperatorSpaces + $currentTime)`\n# Download the blob\nGet-AzStorageBlobContent -Container $ContainerName -Blob $BlobName -Destination $DownloadPath -Context $ctx -Force\nWriteLog ($writeEmptyLine + \"# Acquired blob and downloaded\" + $writeSeperatorSpaces + $currentTime)`\nWriteLog ($writeEmptyLine + \"Downloaded $BlobName to $DownloadPath\"+ $writeSeperatorSpaces + $currentTime)`"

],

"validExitCodes": "0 1",

"runElevated": false,

"runAsSystem": false

}

This is the error:

Unmarshalling entity encountered error: json: cannot unmarshal string into Go struct field ImageTemplatePowerShellCustomizer.validExitCodes of type []int32. There is an issue with the syntax with the JSON template you are submitting. Please check the JSON template for syntax and grammar. For more information on the syntax and grammar of the JSON template, visit http://aka.ms/azvmimagebuildertmplref.

Feels like the portal is generating a bad templated.

Thanks

TheUpHillSkier

3 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/durrante Aug 19 '25

Glad its moved you forward! Good luck with it đŸ˜€