Azure Automation: Script for downloading and preparing AzureRM modules for Azure Automation!

Update from MSFT: 2/22/2016: To respond to a common user question, right now there is no timeline on when additional modules / new versions of modules will be shipped out of box in the Automation service. If you have additional requirements besides what we currently ship globally, these modules / module versions will have to be imported as user modules. Please note the new guidance is that if the latest version of any Azure/AzureRM module is imported as a user module to an automation account, the latest versions of ALL Azure/AzureRM modules (not just the ones that ship out of the box in Azure Automation) should be imported to the automation account, to avoid any version mismatch issues that could occur now or in the future if Azure Automation later ships any additional (or newer version) Azure/AzureRM modules as global modules.


Azure Automation has updated to WMF 5.0 which means that it is no longer required to required to change anything but zip the modules into zip files and upload!

I have simplified this script to do exactly that.

NOTE: The AzureRM Modules are automatically deployed in your account as global modules. Only import your own if you need a newer version or a module that is not shipped out-of-the box yet.

If you do decide to import your own, then please replace all the modules, to make sure you do not have any version mismatches.

this is the script:

# //***************************************************************************
# // Author:	Jakob Gottlieb Svendsen, Coretech A/S.
# // Purpose:   Find, download and zip AzureRM 0.10.0 Modules. 
# //			This script moves the files inside the modules to make them work in Azure Automation
# //            Import AzureRM.profile first, then add any modules you need.
# // CORETECH A/S History:
# // 1.0.0     JGS 10/12/2015  Created initial version.
# // 1.1.0     JGS 10/15/2015  Added rename of AzureRm.Resources\0.10.0 to make it import properly in AzureAutomation + support for other versions than 0.10.0
# // 1.1.2     JGS 02/10/2016  Azure Automation now supports normal folder structure for PS5 modules. Simplified script to not move stuff around
# // 1.1.3     JGS 02/23/2016  Added azure and modules
# //
# // ***** End Header *****
# //***************************************************************************
$folder = "C:\azurePS"

Find-Module -Name AzureRM.*  | Save-Module -force -Path $folder
Find-Module -Name Azure  | Save-Module -force -Path $folder
Find-Module -Name Azure.Storage  | Save-Module -force -Path $folder

$dirs = dir $folder -Directory

$dirs | Foreach {
    $source = $_.FullName
    $destination = "$($_.FullName).zip"
    If(Test-path $destination) {Remove-item $destination}
    Add-Type -assembly ""
    [io.compression.zipfile]::CreateFromDirectory($Source, $destination,[System.IO.Compression.CompressionLevel]::Optimal,$true) 

#//  End Script

Now Import Azure.profile, wait for it to show its activities and then afterwards import all other Azure /AzureRM Modules


NOTE: you can also import them directly from the new built in gallery:


Then use it in a runbook:

$AzureCreds = Get-AutomationPSCredential -Name 'Azure Credentials (Coretech)'
Login-AzureRmAccount -Credential $AzureCreds

$PSDefaultParameterValues = @{
                              "*AzureRmAutomation*:ResourceGroupName" = "blahblah-West-Europe" 
                              "*AzureRmAutomation*:AutomationAccountName" = "blahAutomation"

$runbooks = Get-AzureRmAutomationRunbook

write-warning $runbooks.count

Need training in Service Management Automation (Same techniques can be used in Azure Automation)?

Next run in Stockholm,Sweden

Also available in Denmark, Norway and U.S.. Email me for info.

Comments (4):

  1. Edward Shen says:

    Have you been able to successfully import all of the new cmdlets? I have used your script with limited success – some modules import ok, but others tend to freeze when extracting modules (it will show 0 loaded activities in the module). Does this sound right? The extracting process appears pretty long-winded as well, requiring more than 2 hours for me to upload half of the modules successfully!

    • sorry for the late reply, was trying to make a script for dowqnloading and installing all modules.
      but its Not ready for the public yet.

      I did check all of them, I must have missed one last time, Because I cannot get the APIManagement working. All the others seems to work fine.
      Only exception is that thre Azure.Storage needs to be added before the AzureRM.Storage, since relys on the other.

      I havent been able to find a reason why apimanagement is not working. Will keep trying and post solution if I succeed, before they are added as global modules automatically :)

  2. […] Upload the AzureRM.Resources Module to your Azure Automation account. MVP Jakob Gottlieb Svendsen has described the steps in detail in the following blogpost:… […]

  3. Ray Abueg says:

    Thanks for this info. Worked great, but since I used a more current version of Azure PowerShell (1.0.3), the procedure only works after uploading a current version of AzureRM.Profile since AzureRM.Resources_ depends on it.

Leave a Reply