Reputation: 13
I have a Powershell 7.2 script in an Automation Runbook that drops 18 databases in our lower environment and then restores them from our production environment. The script uses a managed identity. If I have it open in Visual Studio Code, and connect to Azure Runbooks from there, I am able to run it locally without any errors. However, when I publish it to Azure, and run it as "Start Automation Test Job", it fails with the following error:
I have verified the module is installed under the automation account.
I am using this command to import the module. Import-Module -Name Az.Sql -RequiredVersion 5.2.0 -Force
I would appreciate some direction here. I've tried removing the module from the automation account and re-adding it and have the same issue.
Upvotes: 0
Views: 193
Reputation: 7898
This issue is transient and comes when there is a version compatibility conflict.
Firstly, make sure that the version of the Az.Sql
module you're using 5.2.0
is compatible with the Automation Account's runbook runtime version.
And also check the version in your local environment and the Azure automation account if there is any version compatibility conflict.
Refer PowerShell Gallery modules for the above information.
Once you have installed, add the import command in the PowerShell script as given below.
Import-Module Az.sql -Force
In Azure Automation account, module loading takes an ample amount of time so wait until the complete module importing is done.
Also check the Get-Module -Listavailable
to check if it is loaded properly.
I have executed a sample script for dropping databases according to your requirement as shown below and it worked in local vs code without any issues.
Once I deployed it to an automation account, I was able to view the successful results as shown.
If still the issue persists, you can use the Hybrid Worker
in an automation account instead of running directly in Azure.
Upvotes: 0