Update Azure PowerShell modules in Automation

The most common PowerShell modules are provided by default in each Automation account. See Default modules. As the Azure team updates the Azure modules regularly, changes can occur with the included cmdlets. These changes, for example, renaming a parameter or deprecating a cmdlet entirely, can negatively affect your runbooks.

Note

You can't delete global modules, which are modules that Automation provides out of the box.

Important

New Runtime environment experience allows you to manage modules and packages by allowing you to configure the job execution environment. In the new experience, Modules and Packages blades are not available.

Set up an Automation account

To avoid impacting your runbooks and the processes they automate, be sure to test and validate as you make updates. If you don't have a dedicated Automation account intended for this purpose, consider creating one so that you can test many different scenarios during the development of your runbooks. This testing should include iterative changes, such as updating the PowerShell modules.

Ensure your Automation account has added a system-assigned managed identity or user-assigned managed identity.

If you develop your scripts locally, it's recommended to have the same module versions locally that you have in your Automation account when testing to ensure that you receive the same results. After the results are validated and you've applied any changes required, you can move the changes to production.

Note

A new Automation account might not contain the latest modules.

Update Az modules

The following sections explains on how you can update Az modules either through the portal (recommended) or through the runbook.

Update Az modules through portal

Currently, updating AZ modules is only available through the portal. Updates through PowerShell and ARM template will be available in the future. Only default Az modules will be updated when performing the following steps:

  1. Sign in to the Azure portal and navigate to your Automation account.

  2. Under Shared Resources, select Modules.

  3. Select Update Az modules.

  4. Select Module to Update. By default, it will show Az module.

  5. From the drop-down list, select Module Version and Runtype version

  6. Select Update to update the Az module to the version that you’ve selected. On the Modules page, you can view the list as shown below:

    Update AZ modules page with selections.

If you select a version lower than the existing Az module version imported in the Automation account, the update operation will perform a rollback to the selected lower version.

You can verify the update operation by checking the Module version and Status property of the updated modules shown in the list of modules under PowerShell modules.

The Azure team will regularly update the module version and provide an option to update the default Az modules by selecting the module version from the drop-down list.

Update Az modules through runbook

To update the Azure modules in your Automation account:

  1. Use the Update-AutomationAzureModulesForAccount runbook, available as open source.
  2. Download from the GitHub repository, to start using this runbook to update your Azure modules.
  3. Import it into your Automation account or run it as a script. To learn how to import a runbook in your Automation account, see Import a runbook.

Note

We recommend you to update Az modules through Azure portal. You can also perform this using the Update-AutomationAzureModulesForAccount script, available as open-source and provided as a reference. However, in case of any runbook failure, you need to modify parameters in the runbook as required or debug the script as per the scenario.

The Update-AutomationAzureModulesForAccount runbook supports updating the Azure, AzureRM, and Az modules by default. Review the Update Azure modules runbook README for more information on updating Az.Automation modules with this runbook. There are additional important factors that you need to take into account when using the Az modules in your Automation account. To learn more, see Manage modules in Azure Automation.

Use the update runbook code as a regular PowerShell script

You can use the runbook code as a regular PowerShell script instead of a runbook. To do this, sign in to Azure using the Connect-AzAccount cmdlet first, then pass -Login $false to the script.

Use the update runbook

Use the AzEnvironment parameter to pass the correct environment to the runbook. Acceptable value is AzureChinaCloud. These values can be retrieved using Get-AzEnvironment | select Name.

Use the update runbook to update a specific module version

If you want to use a specific Azure PowerShell module version instead of the latest module available on the PowerShell Gallery, pass these versions to the optional ModuleVersionOverrides parameter of the Update-AutomationAzureModulesForAccount runbook. For examples, see the Update-AutomationAzureModulesForAccount.ps1 runbook. Azure PowerShell modules that aren't mentioned in the ModuleVersionOverrides parameter are updated with the latest module versions on the PowerShell Gallery. If you pass nothing to the ModuleVersionOverrides parameter, all modules are updated with the latest module versions on the PowerShell Gallery. This behavior is the same for the Update Azure Modules button in the Azure portal.

Next steps