Unable to load az.accounts module in Automation Account

Chirag Aggarwal 0 Reputation points
2025-11-02T12:15:43.32+00:00

Hi There,

I am using my azure personal automation account with Managed identity, and imported multiple modules such as Az.ResourceGraphexplorer, Az.Accounts and Az.Resources. Getting error as -

The command Connect-AzAccount is part of Azure PowerShell module "Az.Accounts" and it is not installed. Run "Install-Module Az.Accounts" to install it.

Later, I deleted all my imported modules and tried manual import from local machines Zip file(all three modules) still getting the same error.
I am using Runbook 7.2 version. Consequently, I tried running Runbook version 5.1, Az.accounts worked but resourcegraph module failed.

How to resolve the issues?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sandhya Kommineni 2,730 Reputation points Microsoft External Staff Moderator
    2025-11-03T03:28:33.3533333+00:00

    Hello Chirag Aggarwal,

    Thanks for contacting Microsoft Q&A portal

    When using Azure Automation runbooks, ensure that Az modules are compatible with the selected PowerShell runtime version (5.1 or 7.2), as incompatibilities or missing dependencies especially in modules like Az.Accounts can occur due to outdated or leftover AzureRM modules, mismatched versions, or incomplete manual imports from ZIP files, since some Az modules only work with specific runtime versions.

    Recommended Fix:

    • Use the Automation Account’s default Az modules and keep them updated. New Automation Accounts come with the latest Az modules preinstalled. If existing modules have been deleted, perform a full module update from the portal or use the Update Azure Modules option to restore and align all versions and dependencies. Avoid manually importing modules from local ZIP files unless absolutely necessary and you are certain all dependencies are correctly included.

    Refer document: https://learn.microsoft.com/en-us/azure/automation/automation-update-azure-modules

    • PowerShell 7.2, the latest runbook runtime, supports the most recent Az modules, while PowerShell 5.1 is compatible with older modules but may not support newer ones such as Az.ResourceGraph. To prevent module conflicts, choose a single PowerShell runtime version for your runbooks and ensure all Az modules in the Automation Account are updated to versions compatible with that runtime.
    • Use New-AzAutomationModule PowerShell command to import modules directly from PowerShell Gallery to your Automation account. This ensures dependencies are handled.
        New-AzAutomationModule -AutomationAccountName "Contoso17" -Name "ContosoModule" -ContentLink "http://contosostorage.blob.core.windows.net/modules/ContosoModule.zip" -ResourceGroupName "ResourceGroup01"
      

    Refer document: https://learn.microsoft.com/en-us/powershell/module/az.automation/new-azautomationmodule?view=azps-14.5.0

    • Ensure that no AzureRM modules are installed, as they conflict with Az modules especially when using PowerShell 7 or later. AzureRM is deprecated, so it’s recommended to fully migrate to Az modules for compatibility and ongoing support. use Uninstall AzureRM.

    Referral documents:

    I hope the provided answer is helpful, do let me know if you have any further questions on this Please accept as Yes & upvote if the answer is helpful so that it can help others in the community.


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.