Azure Automation: Assets - Modules

Please go through the following articles to understand the basics of Azure automation.

  1. Azure Automation – Basics
  2. Azure Automation: Author Runbook Using PowerShell - Hello World
  3. Azure Automation - Import PowerShell Runbook From Portal Gallery
  4. Azure Automation - Publish Runbook
  5. Azure Automation: Assets – Variables

Azure Automation supports the following type of Assets:

 type of Assets

As per the above screenshot, as of now, by default, when you create an Azure Automation account, it creates 15 modules, by default. Below is the list of the modules that are created by default:

Azure Automation default module list

  • Azure
  • Azure.Storage
  • AzureRM.Automation
  • AzureRM.Compute
  • AzureRM.Profile
  • AzureRM.Resources
  • AzureRM.Sql
  • AzureRM.Storage
  • Microsoft.PowerShell.Core
  • Microsoft.PowerShell.Diagnostics
  • Microsoft.PowerShell.Management
  • Microsoft.PowerShell.Security
  • Microsoft.PowerShell.Utility
  • Microsoft.WSMan.Management
  • Orchestrator.AssetManagement.Cmdlets

In this article, we will learn what are Azure Automation modules and how to create them?

If you are familiar with PowerShell scripts, you would have downloaded few modules. These are similar to the libraries or namespaces that we use in .NET or any other programming language. Azure Automation Runbooks are dependent on the PowerShell cmdlets and these cmdlets are executed by the Azure Automation Worker Servers and these Worker Servers need the modules in order to execute the PowerShell cmdlets.

Let’s see how to import a new module and use the same in our Runbook.

Navigate to the Azure Automation account to which you want to add the new modules and go to Assets, as shown below:

Assets

Now, click on the “Modules” tile and you will be navigated to the list of the existing modules, as shown below:

Modules

There are two ways to add modules to your Azure Automation account.

  • Add a Module from your local drive
  • Add a module from the gallery

Add a Module from your local drive

Click on “Add a Module” icon, which is shown below:

Add a Module

You will be taken to the following page:

page
As per the above screenshot, you can upload a “.Zip” file, whose size is less than or equal to 100 Megabytes.

Currently, I don’t have any modules in my hard disk. Let’s go to script center and search for “Sample PowerShell module”.
Module

Now, click on the “Sample PowerShell module to manage SSH enabled linux hosts, using SMA” and you will be taken to the module’s details page as shown below:
Download

Download the “.Zip” file.

Come back to your Azure Automation account and click “Add a module” link, which is shown below:

module

Provide the download file SSH.zip as an input to the following screen:

download
As soon as you click the “OK” button in the screenshot, given above, it will upload the module and start extracting all the activities (or Cmdlets) into Azure Automation account, as shown below:

account

That’s it. You have added a module successfully to your Azure Automation account. After adding the module, you can use the Cmdlets , available in this module to your Azure Runbook. We will see how to add a Cmdlet from your new module later in this article after looking at how to add a module from the gallery.

Add a module from the Gallery

Let’s now try to add a module from the gallery. Click the “Browse Gallery”, as shown below: 

Add a module

You will see all the available modules in the gallery, as shown below:

Now, click “OK” button, shown in the above screenshot.

Add a module

Let’s select “Posh-SSH” for now. You will be displayed the following screen:

Posh-SSH

Click on the “Import” button of the screenshot, shown above and you will be taken to the following screen:

Import

Click OK, shown in the screen above to import the module to your Azure Automation account. As soon as you click, it will start extracting the Cmdlets, as shown below:

extracting

After a minute or two, you can view the new module posh-SSH in the list of modules, as shown below:

module

That’s it. You have imported a module from the gallery as well. Now, let’s see how to use these modules in our Runbooks.

Use CmdLets to your Runbooks

Navigate to existing Runbooks and select one of your Runbooks and try to edit them.

edit

Click on the “Edit” button, shown in the screenshot above and it will open the Runbook in the edit mode, as shown below:

edit

Expand the “CMDLETS” and you will see both the modules that we have added in the two methods.

methods  
Expand any of the modules to view the Cmdlets available in it. I clicked on “Posh-SSH” and selected “Get-SFTPFile”, as shown below:
Cmdlets

Now, right click on the “Get-SFTPFile” and click “Add to canvas” link, as shown below:

Add to canvas

The selected Cmdlet will be added to your editor pane, as shown below:

 editor pane

That’s it. We have added the required Cmdlet to your Runbook by importing a module to your Azure Automation account.

Conclusion

Azure Automation is based on PowerShell scripts. All PowerShell scripts are categorized as the modules. By default, 15 modules are added automatically to the Azure Automation account. In case you don’t have the required Cmdlet in those 15 modules, you need to search for the required module from the Script center or from the gallery and import the same to your Azure Automation account.

Hope you enjoyed reading the article. Your feedback is highly appreciated.

Up Next
    Ebook Download
    View all
    Learn
    View all