microsoft / ARI

Azure Resource Inventory - It's a Powerful tool to create EXCEL inventory from Azure Resources with low effort
MIT License
1.12k stars 398 forks source link

Automation - Invoke-ARI command was found, but the module could not be loaded #238

Open farreciado opened 3 days ago

farreciado commented 3 days ago

Hello I tried to run ARI in a run book on Azure Automation where I have other runbooks working. Followed the steps to configure a runtime, added needed modules etc.

Runbook it's just one line Invoke-ARI -TenantID "TENANT_ID" -Automation -SkipDiagram -SkipAPIs -StorageAccount "STORAGE_NAME" -StorageContainer "reports" -Debug

When I test the code in test pane, I got this message:

The 'Invoke-ARI' command was found in the module 'AzureResourceInventory', but the module could not be loaded. For more information, run 'Import-Module AzureResourceInventory'.

After checking other issues here, I tried downgrading the Az module version to 8.0, but didn't help.

Packages installed Image

Claudio-Merola commented 2 days ago

Hello @farreciado

The automation test pane streamed any error or issue besides the one you mentioned?

The account seems to be correctly configured and the runbook line is correct.

Did you configured the runtime with powershell version 5.1?

Can you test to change the runbook line to: "Import-Module AzureResourceInventory"?

Just to see what is the error message.

farreciado commented 2 days ago

Hi @Claudio-Merola , I left that single line, now the output is The required module 'PackageManagement' is not loaded. Load the module or remove the module from 'RequiredModules' in the file 'C:\usr\src\PSModules\PowershellGet\PowershellGet.psd1'.

Let me know further tests, thanks.

Claudio-Merola commented 2 days ago

That is odd,

are you using Runtime Environments, Hybrid Workers or the regular AA Runtime?

farreciado commented 2 days ago

Regular runtime, an Azure Automation resource with 3-4 runbooks, used for little things, no configuration beyond what's minimum required

May be worth trying in a separate one?

Claudio-Merola commented 2 days ago

I would suggest to remove the "PowershellGet" module first and see how it goes as apparently that is the module that is giving issues (and it is not really necessary for the script to run)

farreciado commented 1 day ago

I did, but no difference.

I created a new runtime without adding the PowershellGet module. Fails again, showing this warning Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide Exception calling "Initialize" with "1" argument(s): "Object reference not set to an instance of an object." The names of some imported commands from the module 'AzureResourceInventory' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

I tried to uninstall AzureRM to avoid such conflict, with no success.

Claudio-Merola commented 1 day ago

That error should not prevent the Runbook to complete the execution and create the Excel file.

Anyways I updated some components in the module and not with the version 3.5.12 it should work in the automation (even with Runtime 7.4)

Can you test it?