How to keep Your Microsoft Azure Automation Runbook Modules Up-to-Date

I hope that this blog post saves you a couple of hours of debugging when using Azure Automation Runbooks with PowerShell. This article will review a major trap you can find yourself in when using PowerShell in your Azure Runbooks as Azure Automation does not keep your referenced modules up to date. This article will review the issues and will show you how to solve the issue.

API Versions and Module Updates

I wrote a Runbook that would create various objects in an Azure Resource Group, including a storage account, see blog post, How to use Azure Automation PowerShell Runbooks to Create BI PaaS Architectures. This was a script that worked fine from the development laptop as a PowerShell script, but would fail once I created the Runbook.

In the code I have the following command.

New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -Location $locationString -SkuName Standard_LRS -Kind StorageV2

The following error comes up, “A parameter cannot be found that matches parameter name ‘SkuName’.”

This took a bit of head scratching, as the documentation for this New-AzureRmStorageAccount command has this as a valid parameter. On the documentation page, you will see a drop-down box which specifies what version of the Module the document references. Even going back to the 2.3.0 version has the -SkuName parameter.

As pictured above, the latest version is 6.13.0. When you go to your Azure Automation Account screen, under Shared Resources, Modules….

… a listing the current references are provided, such as the following screen capture. As shown the Module Version referenced is 1.0.3.

How do I fix this?

When using references to PowerShell modules, remember that they are not kept up to date automatically, which can make sense in avoiding breaking changes, but can really throw you for a loop when you have strange issues.

As pictured below, on the Modules section, there is an Update Azure Modules menu option. Select that option and all of the modules will update to the latest version.

Warning!!!! You should use a test account and test your code before you do any updates. You could introduce breaking changes. Test, Test, Test.

You will get a notification that the update is complete and the Azure.Storage module is now updated.

DemoAzureAutomationAccount - Modules 
module t e 
Learn about module

The version is now 4.6.1 and the command now works in the script.

How do I keep the Modules Up to Date

There is an option on the menu, Learn about module updates, which provides more detail. It is important to note that Azure Automation will use the latest modules in your Automation account when the Runbook is run as scheduled job. This is where you can get some wild development vs deployment errors coming up.

I had this issue when I was doing Test runs and development of my Runbook, but the error did not show up when I scheduled the job. It had been almost a year since I used this subscription to develop Azure Automation routines and the modules were wildly out of date.

The biggest recommendation when you use these Azure PowerShell modules in your runbooks, you want to run this update process every month or so to make sure that you have the latest versions.

Hope this helps,

Steve Young

Similar Posts