Creating or importing a runbook in Azure Automation

5 min to read Contributors

You can add a runbook to Azure Automation by either creating a new one or by importing an existing runbook from a file or from the Runbook Gallery. This article provides information on creating and importing runbooks from a file. You can get all of the details on accessing community runbooks and modules in Runbook and module galleries for Azure Automation.

Creating a new runbook

You can create a new runbook in Azure Automation using one of the Azure portals or Windows PowerShell. Once the runbook has been created, you can edit it using information in Learning PowerShell Workflow and Graphical authoring in Azure Automation.

To create a new Azure Automation runbook with the Azure Classic portal

You can only work with PowerShell Workflow runbooks in the Azure portal.

  1. In the Azure Classic portal, click, New, App Services, Automation, Runbook, Quick Create.
  2. Enter the required information, and then click Create. The runbook name must start with a letter and can have letters, numbers, underscores, and dashes.
  3. If you want to edit the runbook now, then click Edit Runbook. Otherwise, click OK.
  4. Your new runbook will appear on the Runbooks tab.

To create a new Azure Automation runbook with the Azure portal

  1. In the Azure portal, open your Automation account.
  2. Click on the Runbooks tile to open the list of runbooks.
  3. Click on the Add a runbook button and then Create a new runbook.
  4. Type a Name for the runbook and select its Type. The runbook name must start with a letter and can have letters, numbers, underscores, and dashes.
  5. Click Create to create the runbook and open the editor.

To create a new Azure Automation runbook with Windows PowerShell

You can use the New-AzureRmAutomationRunbook cmdlet to create an empty PowerShell Workflow runbook. You can either specify the Name parameter to create an empty runbook that you can later edit, or you can specify the Path parameter to import a runbook file. The Type parameter should also be included to specify one of the four runbook types.

The following sample commands show how to create a new empty runbook.

New-AzureRmAutomationRunbook -AutomationAccountName MyAccount `
-Name NewRunbook -ResourceGroupName MyResourceGroup -Type PowerShell

Importing a runbook from a file into Azure Automation

You can create a new runbook in Azure Automation by importing a PowerShell script or PowerShell Workflow (.ps1 extension) or an exported graphical runbook (.graphrunbook). You must specify the type of runbook that will be created from the import taking into account the following considerations.

  • A .graphrunbook file may only be imported into a new graphical runbook, and graphical runbooks can only be created from a .graphrunbook file.
  • A .ps1 file containing a PowerShell Workflow can only be imported into a PowerShell Workflow runbook. If the file contains multiple PowerShell Workflows, then the import will fail. You must save each workflow to its own file and import each separately.
  • A .ps1 file that does not contain a workflow can be imported into either a PowerShell runbook or a PowerShell Workflow runbook. If it is imported into a PowerShell Workflow runbook, then it will be converted to a workflow, and comments will be included in the runbook specifying the changes that were made.

To import a runbook from a file with the Azure Classic portal

You can use the following procedure to import a script file into Azure Automation. Note that you can only import a .ps1 file into a PowerShell Workflow runbook using this portal. You must use the Azure portal for other types.

  1. In the Azure Management portal, select Automation and then select an Automation Account.
  2. Click Import.
  3. Click Browse for File and locate the script file to import.
  4. If you want to edit the runbook now, then click Edit Runbook. Otherwise, click OK.
  5. The new runbook will appear on the Runbooks tab for the Automation Account.
  6. You must publish the runbook before you can run it.

To import a runbook from a file with the Azure portal

You can use the following procedure to import a script file into Azure Automation.

Note

Note that you can only import a .ps1 file into a PowerShell Workflow runbook using the portal.

  1. In the Azure portal, open your Automation account.
  2. Click on the Runbooks tile to open the list of runbooks.
  3. Click on the Add a runbook button and then Import.
  4. Click Runbook file to select the file to import
  5. If the Name field is enabled, then you have the option to change it. The runbook name must start with a letter and can have letters, numbers, underscores, and dashes.
  6. The runbook type will be automatically selected, but you can change the type after taking the applicable restrictions into account.
  7. The new runbook will appear in the list of runbooks for the Automation Account.
  8. You must publish the runbook before you can run it.
Note

After you import a graphical runbook or a graphical PowerShell workflow runbook, you have the option to convert to the other type if wanted. You can’t convert to textual.

To import a runbook from a script file with Windows PowerShell

You can use the Import-AzureRMAutomationRunbook cmdlet to import a script file as a draft PowerShell Workflow runbook. If the runbook already exists, the import will fail unless you use the -Force parameter.

The following sample commands show how to import a script file into a runbook.

$automationAccountName =  "AutomationAccount"
$runbookName = "Sample_TestRunbook"
$scriptPath = "C:\Runbooks\Sample_TestRunbook.ps1"
$RGName = "ResourceGroup"

Import-AzureRMAutomationRunbook -Name $runbookName -Path $scriptPath `
-ResourceGroupName $RGName -AutomationAccountName $automationAccountName `
-Type PowerShellWorkflow 

Publishing a runbook

When you create or import a new runbook, you must publish it before you can run it. Each runbook in Automation has a Draft and a Published version. Only the Published version is available to be run, and only the Draft version can be edited. The Published version is unaffected by any changes to the Draft version. When the Draft version should be made available, then you publish it which overwrites the Published version with the Draft version.

To publish a runbook using the Azure Classic portal

  1. Open the runbook in the Azure Classic portal.
  2. At the top of the screen, click Author.
  3. At the bottom of the screen, click Publish and then Yes to the verification message.

To publish a runbook using the Azure portal

  1. Open the runbook in the Azure portal.
  2. Click the Edit button.
  3. Click the Publish button and then Yes to the verification message.

To publish a runbook using Windows PowerShell

You can use the Publish-AzureRmAutomationRunbook cmdlet to publish a runbook with Windows PowerShell. The following sample commands show how to publish a sample runbook.

$automationAccountName =  AutomationAccount"
$runbookName = "Sample_TestRunbook"
$RGName = "ResourceGroup"

Publish-AzureRmAutomationRunbook -AutomationAccountName $automationAccountName `
-Name $runbookName -ResourceGroupName $RGName

Next Steps