Site icon 4bes.nl

Script: Update PowerShell Modules in an Automation Account

If you make use of an Automation Account, you probably have imported some PowerShell Modules from the PowerShell Gallery.
In my experience it is easy to forget about maintaining these modules. Like the modules on your local machine, you want to regular update the modules to make sure your environment keeps up with the latest features and security options. I have created a script to update Automation Account Modules automatically.

Viewing the modules

You can find all the modules in the menu under Shared resources

If you open it, you can get an overview of all modules, their current state and version.

Update Azure Modules

At the top of the screen, you can find a button that says “Update Azure Modules”. This used to trigger a (hidden) runbook that updates the modules automatically.

Today, if you click it, you get a message saying the update feature has been deprecated.

You can follow the link, copy the script and run the runbook manually.
But I wanted to achieve more: I wanted to update all modules, not just the AzureRM/Az-related ones.

So I let the script provided by Microsoft be an inspiration and I created my own version that will update Automation Account Modules. It will update all of them, as long as the source is the PowerShell Gallery.

About the Script

What the script does:

  1. Take all Modules in an Automation Account
  2. Create a ordered list of those modules, while tracking the dependencies
  3. Go through that ordered list, compare the Automation Account version with the version in the gallery and update if needed
  4. Keeps track of the process. If an update fails, the script will throw so you can get aware of it

Notes

The Script

Exit mobile version