Install a PS Module from the PS Gallery in Azure Automation by Script

Hi All !

Azure Automation allows the installation of Modules published on the PS Gallery, or beeing uploaded from a ZIP File.

The ZIP-Upload can be automated with commands from AzureRM.Automation Module, but i was facing the following problem.

When i automatically deploy an Azure Automation Account, how can i install a PowerShell Module from the Gallery automatically ?

It turned out that all the stores its Modules as nuget packages on a Azure Storage Blog account. The next few lines will show you how to find the nuGet Package and install the module from there.

Before using the code, start a VS Code of ISE, or PowerShell Host, and login to your Azure Subscription with Add-AzureRmAccount

1.) Define your Azure Automation environment and the Module you want to install

2.) Define the URL to parse if the module exists on the Gallery

3.) Parse the Module Details

4.) Get the Module Version

5.) Contruct the module content URL

6.) Find the Blob Storage Account with the NuGet Package

7.) Install the Module

The Script is attached to this blog and you can find it below: InstallPSModulesFromGalleryInAzureAutomation

Hope that helps – Good luck when testing !