This is part three of a three part series to get you up and running with Azure Automation. This post creates and executes an Azure Automation run book. You'll need to have followed the other posts to put the foundation components in place.
Here's a reminder of the process and the posts.
- Create a new user in the Azure Active Directory associated with your subscription (this becomes the Automation Credential)
- Assign the user as co-administrator in the subscription
- Create an Azure Automation Account
- Add an Azure Automation Credential
- Add an Azure Automation Variable
- Create a run book that uses the components from posts one and two
- Test the run book
Let's get to it…
Create a Run Book
I've written a validation run book. The code checks that our Automation Account is good to go… that everything we've done so far is valid and allows execution of a run book…
*Save your version of the code as a .ps1 file on your computer.
Now, either create a new run book, using the following steps, or load the above script from the Run Book Gallery ('Browse gallery') within the portal…
New-AzureAutomationRunbook -Name "Validation-Run-Book" -Description "Run book to test we're good to go with Azure Automation" -AutomationAccountName "TheBigBadWolf"
Next, assign the script to the run book.
Set-AzureAutomationRunbookDefinition -Name "Validation-Run-Book" -AutomationAccountName "TheBigBadWolf" -Path .\validation_runbook.ps1 -Overwrite
Notice that the Set-AzureAutomationRunBookDefinition cmdlet has wrapped our script as a workflow. However, if you were to use the Azure Resource Manager module, with the New-AzureRmAutomationRunBook cmdlet you have a -Type parameter with three options: PowerShell, Graph and PowerShellWorkFlow. You also have a -Path parameter to point to the script.
Test the Run Book
Right, now log in to the new portal. Chose 'Edit' (Notice the path at the top of the image: Microsoft Azure / Automation Accounts / TheBigBadWolf / Runbooks / Validation-Run-Book)
Now, chose 'Test Pane'.
Time for some fun! Click 'Start'.
If all has gone well, you should get an output along these lines.
Right, that's everything.
I wanted to detail the steps involved in creating an Azure Automation Account, setting up requisite credentials and variables and then creating and running a run book. I wanted to present the information in a concise manner. Hopefully, I've achieved that…
PS – have a look at this follow-up post: