June 1st, 2015

Using Azure Automation: Part 1

Doctor Scripto
Scripter

Summary: Honorary Scripting Guy, Sean Kearney discusses how to get started with Windows PowerShell and Azure Automation.

Honorary Scripting Guy, Sean Kearney, is here, and for the next five days we're going to touch on Azure Automation, which is a great way to automate control of your Azure resources without Internet access.

Azure Automation is, when you get right down to it, a way to schedule Windows PowerShell workflows in the cloud.

"But wait!" you'll say. "If I want to do that, I can just as easily spin up a virtual machine in Azure and use the scheduled tasks in Windows Server 2012 R2!"

This is true. You could do that. But Azure Automation provides all of that without the need for a irtual machine. It is scalable and (as "The Doctor" would say, "Wait for it…")

…a way to store objects, such as system credentials, in a secure manner.

In the physical world, you might have seen this in action in System Center Orchestrator 2012 R2 with Service Management Automation (SMA). This is effectively SMA in Azure.

Let's start with the first bit. We need to create an instance of Azure Automation, which is yet another cloud service offering. This will only take a moment.

After logging in to the Azure portal, click Azure Automation in the left pane, and choose +NEW to create a fresh instance of Azure Automation.

Image of menu

At this point you can choose Quick Create, which will allow you to spin up an Azure Automation instance with a blank slate and no predesigned jobs.

Image of menu

If you're curious, clicking From Gallery will show you a plethora of templates with predesigned jobs for use in Azure as shown here:

Image of menu

For now, we're going to build a blank runbook and a new Azure Automation account at the same time. The Azure Automation account holds variables and schedules that are unique to a set of runbooks. (You'll hear runbook, but really think "Windows Powershell workflows hosted in Azure.")

We need to supply some information to get this account created:

  • The name we're going to give our runbook (Windows PowerShell workflow)
  • A description of what it's going to do (in the event that our name was written in Klingon or made no sense)
  • The Automation account (we're choosing to create a new one)
  • The name we're assigning to that Automation account (a sensible name)
  • Our subscription in Azure
  • Worldwide region to host it (this should be in the same region as the machines you're going to interact with to minimize any chance of latency)

In our case, from the following example, we're going to create a runbook called HSG-ShutdownAzureVM, which could do ANYTHING, but you can tell that our intent is to have Azure shut down some virtual machines.

Our new Azure Automation account is called HSG-AzureAutomation. We'll click Create, and wait a few minutes as the new instance is automatically created.

Image of menu

When it's done, you'll see a new entry in Azure Automation called HSG-AzureAutomation.

Image of menu

Clicking this instance will allow us to work within it. We will click Runbooks to begin editing our runbook/workflow for shutting down virtual machines in Azure.

Image of menu

The following image shows our runbook called HSG-ShutdownAzureVM:

Image of menu

If we click it, we can see that a basic Windows PowerShell workflow named HSG-ShutdownAzureVM sits before us ready to be created as a draft. Why a draft? Within Azure Automation, you have the ability to have a draft copy of a production script that is being edited and tested before flipping it into production. Nice, eh?

Image of menu 

So we now have the most basic building blocks for some Azure Automation—an Azure Automation account and a runbook.

By the way, do you want to know the fastest way to do all this? Two little Windows Powershell cmdlets are all that is needed, which are a part of the Azure module for Windows PowerShell. There is one to create the Azure Automation account and one to create the runbook! So this same process done in Windows PowerShell would have looked like this:

$AutomationAccountName='HSG-AzureAutomation'

$NewRunbookName='HSG-ShutdownAzureVM'

$NewRunbookDescription='ShutdownAzureVM with Azure Automation'

$Location='East US'

New-AzureAutomationAccount -name $AutomationAccountName -location $Location

New-AzureAutomationRunbook –Name $NewRunbookName -Description $NewRunbookDescription –AutomationAccountName $AutomationAccountName

Pop by tomorrow and we'll get into some actual scripting with Azure Automation!

I invite you to follow The Scripting Guys on Twitter and Facebook. If you have any questions, send an email to The Scripting Guys at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, remember eat your cmdlets each and every day with a dash of creativity.

Sean Kearney, Windows PowerShell MVP and Honorary Scripting Guy 

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.