An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Jason R. Coombs Thanks for the detailed repro. Based on the logs and your script, there are two concrete issues to fix:
- Cmdlets are called before the module is loaded
-
Disable-AzContextAutosave,Connect-AzAccount, andSet-AzContextlive in Az.Accounts. In your script they’re invoked beforeImport-Module Az.Accounts, so the job can’t resolve them. - Fix: import Az.Accounts first, then call those cmdlets
- Reference: https://learn.microsoft.com/en-us/powershell/module/az.accounts/disable-azcontextautosave?view=azps-15.1.0
-
- Assembly dependency mismatch for the 7.2 sandbox
- The errors about
Azure.CoreandMicrosoft.Identity.Client.Extensions.Msalshow the Az module set for 7.2 isn’t fully aligned in the sandbox. The supported way to repair this in Azure Automation is to refresh the default Az module set for the 7.2 runtime (which rehydrates dependency chains). If “latest” blocks you from updating, roll back to a lower Az set and then upgrade—this forces a rebuild of the module graph. - Reference: https://learn.microsoft.com/en-us/azure/automation/automation-update-azure-modules
- The errors about
Please try below workarounds:
Refresh the Az module set for PowerShell 7.2
- In the portal: Automation Account → Shared resources → Modules → Update Az modules.
- Select Runtime version = 7.2 and a stable Az version (e.g., 11.2.0). Click Update.
- If the UI says you’re already on the latest, choose an earlier Az version (e.g., 8.x) to roll back, then run Update again to move back to 11.2.0. This rollback/upgrade path is supported and rebuilds dependencies.Wait for all default Az modules to show Status = Available under the 7.2 runtime.
If you’re using the newer Runtime Environment experience, prefer a runtime with PowerShell 7.2 and defaultPackages { Az: '11.2.0' }, then assign that runtime to your runbook. It cleanly isolates module versions per runtime.
Remove “helper” commands you don’t need
-
Register-AzModuleisn’t required in Automation runbooks; delete it from your script. The module loader plusImport-Moduleis sufficient.
Fix your runbook ordering (minimal working sample)
Use this exact order so cmdlets resolve after the module is loaded:
# Show runtime
Write-Output "PS: $($PSVersionTable.PSVersion)"
Write-Output "ModulePath: $env:PSModulePath"
# 1) Import modules FIRST (stop on failure)
Import-Module Az.Accounts -ErrorAction Stop
Import-Module Az.Storage -ErrorAction Stop
# 2) Context hygiene + auth
Disable-AzContextAutosave -Scope Process
$ctx = (Connect-AzAccount -Identity).Context
Set-AzContext -DefaultProfile $ctx | Out-Null
# 3) Verify modules resolved
Get-Module -ListAvailable Az.Accounts, Az.Storage |
Select-Object Name, Version, ModuleBase
This resolves your specific errors:
- CommandNotFound for Disable/Connect/Set: Occurs when Az.Accounts isn’t loaded yet. Importing the module before calling those cmdlets fixes it.
-
Azure.Core/ MSAL extension load failures: The Update Az modules action refreshes and aligns the dependency chain that Az modules rely on for 7.2 jobs; rollback then upgrade is the supported way to force a rebuild when “latest” blocks an update.
If problems persist after the refresh:
Azure’s cloud sandbox has known limits; certain module/assembly loads can still fail depending on versions and calls. The supported workaround is to run the job on a Hybrid Runbook Worker (extension‑based), which executes outside the sandbox and avoids these load constraints.
Reference: https://learn.microsoft.com/en-us/azure/automation/shared-resources/modules#sandboxes
Are you using the classic Modules blade or the Runtime Environment (Preview) experience for this Automation Account?
Thanks,
Suchitra.