Udostępnij za pośrednictwem


Getting Started with Azure Automation Services

Azure Automation Services allows you to automate tasks you would do in Azure.  You could write Power Shell scripts to run on premises and connect to Azure, but Automation services hosts those scripts in Azure and you can schedule them to run on a regular basis all in Azure. There no dependencies on a machine on premises being up available and connected with Azure Automation Services.

To get started you will need to establish a security context for your task to run.  There are two ways of doing this, entering a users name / password combination (PowerShell) or by using a certificate.

For this example I will use the user name / password combination.

Entering Credentials

Log in to your Azure portal and select Automation Services on the left hand side of the page:

If you do not have an automation account set up, you will need to create one now.

Click on Create an Automation Account

Select a name and a region where you want the account to run.

Click the check to create your account.

You will be taken to the Automation Screen and your account will be listed, double click on your account.

You will see the dash board with a list of things to do under getting started.

Before we do any of those things you will need to establish a credential for the Run Books to use to gain access to your Azure Account.

Click on Assets

At the bottom of the screen click on Add Setting

Click on Add Credential

In Credential Type Select Windows PowerShell Credential and give it a name

On the next screen enter you Azure Credentials (user/pass) and click the check.

You now have credentials to use to Authenticate RunBooks

Creating a Run Book

Now Click on RunBooks

 

Click on New in the bottom left corner of the screen.

You can choose from a Gallery of existing runbooks or you can create your own.

In this case I will have you do a simple Hello World example just to get you started.

Click on RunBooks

Click New and select RunBook and Quick Create.  Provide your runbook a name and select a subscription (make a note of your subscription name, you will need it later) and a region for the run book to run.

Once created double click on your run book and select Author

You will see three lines of code defining your workflow.  Between the two brackets, type the following.

    
    $Cred = Get-AutomationPSCredential -Name "yourcredential"  
    $SubscriptionName = "Your Subscription Name"
   
    Add-AzureAccount -Credential $Cred
   
    Select-AzureSubscription -SubscriptionName $SubscriptionName

    InlineScript {
   
        Write-Output "Hello World"

    }

Replace yourcredential with the name of the credential you created in the previous step.

Replace Your Subscription Name with the name of your subscription.

Now you can test your run book by clicking the test button

After a successful run you will see something similar to this.

Now you have the ability to run any Powershell you want in Azure Automation Services, there are a large number of runbooks in the Gallery that you can run as is or modify to do what you want, or you can write your own.

Enjoy