Please go through the following articles, to understand the basics of Azure Automation.
- Azure Automation – Basics
- Azure Automation: Author Runbook Using PowerShell - Hello World
- Azure Automation - Import PowerShell Runbook From Portal Gallery
- Azure Automation - Publish Runbook
Azure Automation supports the following type of Assets:
In this article, we will learn what Azure Automation Variables are and how to create them.
Asset Variables are similar to the variables that are usually used in the Programming languages. Variables are used to store a value that could be used in multiple places within the runbook. The Azure Variables are accessible across multiple runbooks within the Azure Automation Account. You could use Variable to store the name of the VM that you would like to Start or Stop, based on your requirement. You can access these variables within the PowerShell that you write within your runbook. While creating a variable, you can also specify if you would like it to be stored in encrypted format.
Please also note that these variables are persisted, so you can use the same for multiple execution of the Runbooks.
You can retrieve the value of the variable using the cmdlet Get-AzureAutomationVariable. However, you need to use Get-AutomationVariable cmdlet to retrieve the encrypted variables.
We can create the following type of Azure Automation Asset variables.
- String
- Boolean
- DateTime
- Integer
- Not Specified
If you would like to create a variable of any other type not specified above, you need to go for PowerShell.
The portal provides different controls for each of the above variable types. Let’s go ahead and create a variable for each one of the data types, specified above.
Navigate to the Settings blade of the Azure Automation Account and click on Assets, as shown below, to view the Assets blade:
Now, click on “Variables” tile of the above screen to navigate to the variables listing blade. As shown below, currently there are no variables.
Let’s create all the five variable types mentioned above.
Let’s start with creating a String variable
Now, click on the “Add a variable” link of the above screen capture and you will see a form, as shown below.
Provide a meaningful name and description for your string variable.
In the above screen, the “Value” field is a textbox, so we can enter a string value to the “String” value.
Now, click on “Create” button to create the “MyString” variable. You will see the new variable, as shown below.
Let’s create a second type of variable – Boolean Variable. Click on “Add a variable” in the above screen and select “Boolean” in the “Type” field.
Because we selected “Boolean” in the “Type” dropdown, the value field is now a dropdown with “True” and “False” options, as shown below.
Click on “Create” button and create the variable.
Let’s create a third type of variable – DateTime Variable. Click on “Add a variable” in the above screen and select “DateTime” in the “Type” field. As shown below, click on create button.
We get Date and Time controls in the “Value” field. Please note that this is UTC time.
Let’s create a fourth type of variable – Integer Variable. Click on “Add a variable” in the above screen and select “Integer” in the “Type” field.
Please note that if you try to provide a non-integer value in the “Value” text, you will see an error message, as shown below.
Please provide a valid integer value and click on “Create” button to create the integer variable.
Below is the list of all the variables.
You can also encrypt a variable, if required. For example, if you would like to hide some sensitive information from all other co-administrators, you can encrypt that information by enabling the “Encrypted” field, as shown below.
Click “Create” button to create the variable. In the listing page, you will see the encrypted value masked by asterisk, as shown below.
That’s it. We have learned how to create Asset variables in the Azure Automation Account. Please provide your feedback in the comments.