AZ modules cmdlets is failing in automation runbooks using powershell scripts

Perumal, Janakiraman 241 Reputation points
2020-10-20T15:22:52.523+00:00

Hi Team,

Get-AzVM : The term 'Get-AzVM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I am getting the error only while executing this from runbook within automation powershell.

When i execute from the cloud shell, i am getting the expected results. I noticed the same error for all the AZ modules commands.

i have tried to update the modules as mentioned in the document, but it didnt work out. Any help is much appreciated.

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

Accepted answer
  1. Andreas Baumgarten 91,526 Reputation points MVP
    2020-10-21T06:58:18.78+00:00

    It's not possible to mix the Az and AzureRM module as fa as I know in the same PowerShell script.

    For that reason I would add and use the Az modules only.

    Get-AzVM is part of the Az.Compute module and this module is related to the Az.Account module you need to authenticate.

    In your Automation Account verify the modules:

    33896-aam.jpg

    If the Az.Account and Az.Compute modules are missing you can add these 2 modules via Module Gallery to your Automation Account.

    33897-aamg.jpg

    If this is done you are able to use the cmdlets of both modules in your PowerShell Runbook.

    Just import the modules at the beginning of your script:

    Import-Module Az.Account  
    Import-Module Az.Compute    
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 91,526 Reputation points MVP
    2020-10-20T19:02:44.42+00:00

    You added the modules Az.Account and Az.Compute in your Automation Account?

    If done you need to authenticate:
    https://learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-powershell#step-5---add-authentication-to-manage-azure-resources

    If done Get-AzVM should work in your PowerShell Runbook.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten