Please go through the following articles to understand the basics of Azure automation.
- Azure Automation – Basics
- Azure Automation: Author Runbook Using PowerShell - Hello World
- Azure Automation - Import PowerShell Runbook From Portal Gallery
- Azure Automation - Publish Runbook
- Azure Automation: Assets – Variables
Azure Automation supports the following 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:
Now, click on the “Modules” tile and you will be navigated to the list of the existing modules, as shown below:
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:
You will be taken to the following 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”.
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 the “.Zip” file.
Come back to your Azure Automation account and click “Add a module” link, which is shown below:
Provide the download file SSH.zip as an input to the following screen:
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:
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:
You will see all the available modules in the gallery, as shown below:
Now, click “OK” button, shown in the above screenshot.
Let’s select “Posh-SSH” for now. You will be displayed the following screen:
Click on the “Import” button of the screenshot, shown above and you will be taken to the following screen:
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:
After a minute or two, you can view the new module posh-SSH in the list of modules, as shown below:
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.
Click on the “Edit” button, shown in the screenshot above and it will open the Runbook in the edit mode, as shown below:
Expand the “CMDLETS” and you will see both the modules that we have added in the two 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:
Now, right click on the “Get-SFTPFile” and click “Add to canvas” link, as shown below:
The selected Cmdlet will be added to your editor pane, as shown below:
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.