question

PerumalJanakiraman-5353 avatar image
0 Votes"
PerumalJanakiraman-5353 asked azure-cxp-api edited

AZ modules cmdlets is failing in automation runbooks using powershell scripts

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
2 Votes"
AndreasBaumgarten answered PerumalJanakiraman-5353 commented

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



aam.jpg (538.7 KiB)
aamg.jpg (917.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello Andreas,

The solution worked as expected. Thanks a lot for your support and sharing the details.

Regards,
Janakiraman

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered PerumalJanakiraman-5353 commented

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

If done you need to authenticate:
https://docs.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




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello Andreas,

I tried update modules as per the document and below runbook.

https://github.com/Microsoft/AzureAutomation-Account-Modules-Update

I have tried the step 5, which you mentioned, but it also failed.

I am new to Azure and runbook, so i am not sure if the update has worked. Is there a way to verify that?

Regards,
Jana.

0 Votes 0 ·