Script Sample - Export All Azure Automation Account Runbooks and Variables

@20aman    Jul 16, 2018

When you work with Azure Automation, you build lots of Runbooks over time. When the volume grows, you can't just export each and every Runbook one by one. Add to it the fact, if you have multiple Azure Automation accounts. It becomes a nightmare to download all the Runbooks one by one.

There are two ways to export all the Runbooks all at once.

First method - Using Azure Automation PowerShell ISE Add-On

You can install the Azure Automation PowerShell ISE Add-on and connect to your Azure Automation Account. Then you can download all the Runbooks locally and copy the same. This Add-On can be downloaded from GitHub or PowerShell gallery as per the instructions provided here: Azure Automation PowerShell ISE Add-On

Second method - Using this script sample

This script sample requires you to update the input variables for your environment i.e. related to your subscription, Azure Automation account name etc. Then it connects to the Azure using below cmdlet.

Add-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName $SubscriptionName

Then it exports the Azure Automation Runbooks using below cmdlets. Here it first fetches all the Runbooks and then uses "Export-AzureRmAutomationRunbook" cmdlet to export these to a local folder.

$AllRunbooks = Get-AzureRmAutomationRunbook -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
$AllRunbooks | Export-AzureRmAutomationRunbook -OutputFolder $OutputFolder

Finally, it exports the variables in the environment by using the below cmdlets. Here it first fetches the variables and then uses "Export-Csv" cmdlet to export the variables to a csv file.

$variables = Get-AzureRmAutomationVariable -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
$variablesFilePath = $OutputFolder + "\variables.csv"
$variables | Export-Csv -Path $variablesFilePath -NoTypeInformation

Location of the script

This script is located in the Github here: Export Azure Automation Runbooks and Variables





Comments powered by Disqus