Variable assets in Azure Automation

Variable assets are values that are available to all runbooks and DSC configurations in your automation account. They can be created, modified, and retrieved from the Azure portal, Windows PowerShell, and from within a runbook or DSC configuration. Automation variables are useful for the following scenarios:

  • Share a value between multiple runbooks or DSC configurations.
  • Share a value between multiple jobs from the same runbook or DSC configuration.
  • Manage a value from the portal or from the Windows PowerShell command line that is used by runbooks or DSC configurations, such as a set of common configuration items like specific list of VM names, a specific resource group, an AD domain name, etc.

Automation variables are persisted so that they continue to be available even if the runbook or DSC configuration fails. This also allows a value to be set by one runbook that is then used by another, or is used by the same runbook or DSC configuration the next time that it is run.

When a variable is created, you can specify that it is stored encrypted. When a variable is encrypted, it is stored securely in Azure Automation, and its value cannot be retrieved from the Get-AzureRmAutomationVariable cmdlet that ships as part of the Azure PowerShell module. The only way that an encrypted value can be retrieved is from the Get-AutomationVariable activity in a runbook or DSC configuration.

Variable types

When you create a variable with the Azure portal, you must specify a data type from the drop-down list so the portal can display the appropriate control for entering the variable value. The variable is not restricted to this data type, but you must set the variable using Windows PowerShell if you want to specify a value of a different type. If you specify Not defined, then the value of the variable is set to $null, and you must set the value with the Set-AzureRMAutomationVariable cmdlet or Set-AutomationVariable activity. You cannot create or change the value for a complex variable type in the portal, but you can provide a value of any type using Windows PowerShell. Complex types are returned as a PSCustomObject.

You can store multiple values to a single variable by creating an array or hashtable and saving it to the variable.

The following are a list of variable types available in Automation:

  • String
  • Integer
  • DateTime
  • Boolean
  • Null

Read more