Azure Virtual Desktop: Custom Image Template Fails with PowerShell Script in Azure VM Image Builder

Casey Hansen (SA) 0 Reputation points
2026-09-15T00:11:34.95+00:00

Problem description

I am creating an Azure Virtual Desktop custom image template using Azure VM Image Builder. The process fails when I include a PowerShell customizer script stored in Azure Storage and referenced by URL. The error reported is a generic internal failure: 'Internal error occurred. This is a generic error. To identify possible causes, go to https://aka.ms/azvmimagebuilderts.' When I remove the custom script, the template creation succeeds.

Environment

Azure VM Image Builder for Azure Virtual Desktop, using a PowerShell script hosted in Azure Storage with access control via RBAC. The storage account has both private endpoint and public access enabled with anonymous blob access for the container.

What I've already tried

I tested the template with the PowerShell customizer script included and removed. When included, template creation fails; when removed, it succeeds. I verified that the script URI points directly to the blob file and that the SAS URL is correctly formatted. I attempted using a SAS token with read-only permissions and a short expiry. I also confirmed that the storage account allows anonymous access and that the URL works in a browser. I reviewed the guidance on storage SAS, network access, and template configuration. I checked that the build VM can reach the storage endpoint and that the script URL is not a container or portal link. I verified the storage account's network rules and SAS token permissions.

Current status

The template only succeeds when the storage account is publicly accessible with anonymous blob access enabled. Using a SAS URL does not resolve the issue. The root cause appears to be that VM Image Builder cannot reach the script blob with the current access settings, possibly due to network restrictions or incorrect script URL formatting. I am seeking guidance on how to configure the storage and script URL properly to enable successful template creation without making the storage account fully public.

Azure Virtual Desktop
Azure Virtual Desktop

A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.


1 answer

Sort by: Most helpful
  1. Alex Burlachenko 25,285 Reputation points MVP Volunteer Moderator
    2026-09-15T07:02:40.07+00:00

    Hi Casey Hansen (SA) & thx for join me at Q&A platform,

    fact that the build succeeds only when anonymous blob access is enabled strongly suggests that the failure is occurring while Azure VM Image Builder retrieves the PowerShell script, not while the script itself executes.

    For AVD Custom Image Templates, the supported way to keep the blob private is to use the managed identity selected for the image template and grant that identity Storage Blob Data Reader on the script container or blob. Microsoft explicitly documents this for custom scripts stored in Azure Storage. Microsoft Learn I would prefer that over SAS; current Image Builder guidance also recommends managed identity rather than embedding SAS credentials in scriptUri.

    There is a second, separate issue if the Storage account has network restrictions. A SAS only handles authorization; it doesn't bypass the Storage firewall or private-endpoint routing. For firewall-protected Storage, current Image Builder networking guidance requires the appropriate build/ACI subnet topology and Storage network access from that path. So a URL working in your browser doesn't prove that the Image Builder service can retrieve it.

    I’d also check customization.log rather than relying on the generic Internal error occurred message. The failed build's IT_<resource-group><template>... staging resource group contains the packerlogs container, and the log should show whether retrieval is returning 403, failing DNS/network connectivity, or failing later during PowerShell execution.

    So I wouldn't enable anonymous blob access as the permanent workaround. Use a private container, grant the template's UAMI Storage Blob Data Reader, use the normal blob URI without a SAS, and then make sure the Image Builder network path is permitted by the Storage account. If that exact configuration still returns an internal error while customization.log shows the identity successfully reaching Storage, then it becomes an Azure VM Image Builder issue worth escalating with the build operation ID and log.

    rgds,

    Alex

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.