lombahdo
lombahdo

Reputation: 11

Cannot Import Any Modules into Azure Runbook

I am having a problem importing Azure modules into a runbook, something that I thought would be easy. Any module I try (Import-Module modulename) and I just run a test to see if I can connect I get the error message. This is an example of an error message:

Import-Module : The specified module 'Az.ServiceFabriv' was not loaded because no valid module file was found in any module directory. At line:1 char:1 + Import-Module -Name Az.ServiceFabriv + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (Az.ServiceFabriv:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

I can go to the module library and pick any module that is in there and it does not work. I assume I am missing something small, but if anyone can help point me in the right direction I would appreciate it.

Upvotes: 0

Views: 453

Answers (1)

Jahnavi
Jahnavi

Reputation: 8018

Cannot Import Any Modules into Azure Runbook:

The specified module 'Az.ServiceFabriv' was not loaded:

I could see that the module name is not correctly given here. It should be Az.ServiceFabric but not Az.ServiceFabriv. Make sure that there are no naming errors while providing module names.

By referring to the PowerShell Gallery modules, you can directly deploy the required module to Azure Automation as shown below.

enter image description here

The module has been loaded successfully:

enter image description here

If still the issue persists with the above approach, you can directly use below command in an automation runbook, and it worked for me as well.

Import-Module -Name Az.ServiceFabric

enter image description here

Note: You need to have an Automation contributor role assigned to the corresponding managed identity in an Azure Automation runbook.

And also as suggested by @Riley Carney, try using New-AzAutomationModule command to import the modules using PowerShell.

New-AzAutomationModule -AutomationAccountName "autolatest" -ResourceGroupName "Jahnavi" -Name <module> -ContentLinkUri "https://www.powershellgallery.com/api/v2/package/<module>/<Version>"

Upvotes: 1

Related Questions