Configure an Azure Automation Account - Part 2 - Credentials and Variables

Welcome back!

This is part two of a three part series to get you up and running with Azure Automation. The end goal is the execution of an Azure Automation run book.

Here's a reminder of the process and the posts.

Post 1

    1. Create a new user in the Azure Active Directory associated with your subscription (this becomes the Automation Credential)
    2. Assign the user as co-administrator in the subscription
    3. Create an Azure Automation Account

 

Post 2

    1. Add an Azure Automation Credential
    2. Add an Azure Automation Variable

 

Post 3

    1. Create a run book that uses the components from posts one and two
    2. Test the run book

 

Onwards!

To be able to execute code in an Azure Automation run book, you'll need a credential. We created a suitable account in post one and now we need to make it available to a run book.

 

Add an Azure Automation Credential

In part one, we created an Azure Automation Account called 'TheBigBadWolf'. We also created a user called 'Anne Droid', a co-administrator of the Azure subscription. Let's bring the two together.

$cred = Get-Credential -UserName "AnneDroid@ninja-injury.com" -Message "Azure Automation Credential"

 

New-AzureAutomationCredential -AutomationAccountName "TheBigBadWolf" -Name "AzureWolfCredential" -Description "Automation Credential for TheBigBadWolf" -Value $cred

    

 

That's it!

NB - it's worth noting that you may need to use Add-AzureAccount to log back in prior to running New-AzureAutomationCredential... post one was a week ago, after all!

We now have a credential associated to an automation account in the subscription. It also has the necessary permissions to execute run book code... but how do we identify the subscription to the run book? Read on.

 

Add an Azure Automation Variable

New-AzureAutomationVariable -Name "WolfSubscriptionId" -Description "Automation Variable for TheBigBadWolf" -Value "d2d4814c-cb9d-4849-8990-88fc7e7cade2" -Encrypted $false -AutomationAccountName "TheBigBadWolf"

 

Easy. We now have the foundation components to execute a run book in Azure: an execution credential and a variable that references the subscription. 

Next time out we'll create, test and schedule a run book.