One of the most popular automation tools is Azure Automation and this will be a series of posts covering the introduction to Azure Automation, creating automation runbooks, dealing with assets, testing and publishing runbooks.
Nowadays, automation is regarded as a significant skill to acquire when you’re in the IT service industry. Not just for DevOps, but even for ITOps and SysAdmins. Automation can be considered as a train that you either get on to or get left behind or worse, be run over by it.
Learning automation is one way to upgrade your skillset. To some degree, your worth would also increase, and you may be considered as one of the valuable members in your team or your company as a whole.
What is Azure Automation
Azure Automation is one of the services available in Azure. It enables you to deploy and run PowerShell scripts without having to use a virtual or physical machine.
With Azure Automation, you can deploy your scripts serverless. There’s also no need to deal with having to set up Task Scheduler interval. This can also eliminate the risk of exposing credentials because can be saved as assets instead of saving them in plain text files.
When to use Azure Automation
There could be many reasons why Azure Automation can be used. These are some of the things you may want to consider.
- When the task does not require user interaction.
- When the task is repetitive.
At this day and age, there are fewer tasks that cannot be considered for automation. Some may seem like they cannot be automated. But sometimes, with a little creativity, there’s not much that you can’t automate.
In the end, through continued use and practice, you will be able to determine with much more confidence when and when not to use Azure Automation.
What You Need to Work with Azure Automation
In this series, there will be demos and examples. You need to have the following to effectively follow along.
- Working knowledge of Azure.
- You must be able to read, understand and write PowerShell scripts.
- An Azure subscription. If you do not have this yet, you can sign up for a free trial.
- A computer with PowerShell 5.1 (or above).
- The Azure PowerShell Module must be installed. If you don’t have this yet, please go to the Install the Azure PowerShell module page for more information.
Throughout this series, I will be using my Visual Studio Enterprise subscription to show you the demos and examples working with Azure Automation.
I will also show the demos using the Azure Portal and PowerShell whenever possible. Using the portal may be convenient for some, but using PowerShell is highly recommended.
Logging in to Azure
Before you can do anything with Azure Automation, you must be logged in to Azure first. There are two ways you can be logged in.
- Graphical User Interface (GUI)
- Using the Azure PowerShell Module
Note that the Azure Portal and the Azure Portal Desktop App are the same. They are both GUI-based, and the only difference is that the Azure Portal is accessed using a Web Browser, while the Azure Portal Desktop App accesses the Azure Portal using a dedicated app.
Login using the Portal
Using any browser of your choice, navigate to https://portal.azure.com. Then you will be asked for your login credentials. Enter your username then click Next.
Enter your username
Then you will be asked to enter your password, click Sign in.
Enter your password
And you will be taken to the Microsoft Azure homepage.
Microsoft Azure homepage
Login Using PowerShell
Note that before you can use PowerShell with Azure, you must make sure that the PowerShell Az module is installed. Otherwise, you will not be able to use the Azure commands in PowerShell.
Open a PowerShell session and log in to Azure using the command below.
Just like when logging in using the Azure Portal, you will be prompted for your username, then your password similar to the screenshots you see below.
Enter your username
Enter your password
Once login is successful, you will see a similar output as shown below in the PowerShell console.
Login to Azure is successful
Knowing the Different Azure Automation Resources
There are five (5) Azure automation resources that you must be familiar with. Below are the short descriptions for each.
To use Azure, you pay a fee for subscription. This is to say that you do not own the resources, you are just being permitted to use them as part of your subscription.
Resource Group is used to logically group Azure resources like virtual machines, IP addresses, DNS Zones and so on. And these Resource Groups belong to or are created under a subscription.
This resource is specific to Azure Automation. It is located inside a resource group when created. In a way, it is similar to a resource group because it acts as a logical container but only specific to Azure Automation.
A runbook is simply a PowerShell script that runs in Azure. It is what’s in the center of your automation projects.
These are the items stored in the automation account that can be accessed and used by runbooks. These could be credentials, variables, and schedules, among others.
Creating a New Azure Automation Account
Remember that Automation Accounts are located inside resource groups, and resource groups below to specific subscriptions.
To create an Automation Account you need to consider which subscription you will use (if you have multiple subscriptions) and whether you will use an existing resource group or create a new one.
In this article, I will demonstrate how to create an Automation Account using the Web Portal and PowerShell.
Create an Automation Account using the Portal
First, log in to the Azure Web Portal. And once you’re logged in, click the Create a resource button.
Create a resource
From the Azure Market Place page, search for ‘Automation.’
Search for ‘Automation’
Once you are presented with the page to create the Automation account, click Create.
Click the ‘Create’ button
Then you will see the Add Automation Account form.
- Give the automation account a name. I will use the name Azure-AA.
- Next, select the Subscription to use. I am using my Visual Studio Enterprise.
- Click on the Create new link to create a new resource group where the automation account will be created.
- Type in the name of the new resource group. I am using Azure-AA-RG.
- Then click OK.
Fill in the name, subscription, and create resource group
- Next, select the location appropriate to you. I am using the East US region as the location.
- Click Create
Select the location
Now, wait for the Automation account to be created. Once the automation account is created, you can go to All Resources and verify that the Automation Account is listed in the list of resources.
Click on the All Resource button
The new Azure Automation Account is created
Create an Automation Account using PowerShell
The first step is to choose which Azure subscription to use.
Open PowerShell and connect to Azure. Then select your Azure subscription by using these command:
Select-AzSubscription <subscription name>
Select an Azure Subscription
Next, create a resource group where the new Azure Automation Account will be created.
The command below will create the resource group with name Azure-AA-RG and the location is the EastUs region.
New-AzResourceGroup -Name 'Azure-AA-RG' -Location 'EastUS'
Creating a new resource group
Next, create the Automation Account. The command below will create the automation account with the name of Azure-AA, the location is EastUS and inside the resource group Azure-AA-RG
New-AzAutomationAccount -Name 'Azure-AA' -Location 'EastUS' -ResourceGroupName 'Azure-AA-RG'
Create a new automation account
In this article, you’ve learned how to login to Azure using the Portal and PowerShell. You also learned what the different Azure Automation resources are and how to create a new Azure Automation Account. You also gained a little insight on when and when not to use Azure Automation.
In the next article, I will show you how to create your first Azure Automation Runbook. Thank you for reading and stay tuned!