TL;DR

Newer Az PowerShell module versions (newer than v11) may fail to load in Azure Automation PowerShell runbooks on older runtime versions like 7.2. Switch to the Runtime Environment Experience, create a new Runtime Environment, select a new PowerShell version like 7.4 or 7.6 for the environment, and migrate your runbooks to the new environment.

Issue

If your Azure Automation PowerShell runbook job output lights up like a 🎄 and you see warning/error messages like these

  • ⚠️ Unable to find type [Microsoft.Azure.PowerShell.AuthenticationAssemblyLoadContext.AzAssemblyLoadContextInitializer].

  • ⛔ Import-Module: Could not load file or assembly 'Microsoft.Identity.Client.Extensions.Msal, Version=4.83.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. The system cannot find the file specified

  • etc.

chances are you try to load newer Az PowerShell module versions (newer than v11) while your runbook runtime version is 7.1/7.2.

The issue does not seem to be related to those older PowerShell version, the Az modules may work fine with these versions of PowerShell outside of Azure Automation (⚠️ though the PowerShell team no longer supports them1). The issue seems to be related to the Azure Automation "sandbox" (or whatever the correct name for it is) for those older PowerShell versions.

Solution

Migrate your Azure Automation runbooks to a newer PowerShell runtime version (e.g. 7.4 or 7.6).

If like me, you can't see these newer PowerShell runtime versions (released June 2025 and April 2026) you have to update your Azure Automation Account to use the new Runtime Environment Experience.2

Then under Process Automation / Runtime Environments you can create a new runtime environment3 for PowerShell version 7.6 for example, add the PowerShell modules you need and save it (you can install more modules later).

Now, when you update the runtime environment of existing runbooks4 or create new runbooks, you can select the runtime environment you just created.

This solved the issues for me and PowerShell scripts with newer Az PowerShell modules now load those modules successfully 🎉