Skip to content

Latest commit

 

History

History
108 lines (82 loc) · 7.44 KB

automation-creating-importing-runbook.md

File metadata and controls

108 lines (82 loc) · 7.44 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.devlang ms.topic ms.tgt_pltfrm ms.workload ms.date ms.author
Creating or importing a runbook in Azure Automation
This article describes how to create a new runbook in Azure Automation or import one from a file.
automation
georgewallace
jwhit
tysonn
24414362-b690-4474-8ca7-df18e30fc31d
automation
na
article
na
infrastructure-services
09/29/2017
magoedte;bwren

Creating or importing a runbook in Azure Automation

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 portal

  1. In the Azure portal, open your Automation account.
  2. From the Hub, select Runbooks 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), an exported graphical runbook (.graphrunbook), or a Python 2 script (.py extension). You must specify the type of runbook that is created during 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 is converted to a workflow, and comments are included in the runbook specifying the changes that were made.

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. From the Hub, select Runbooks 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 is automatically selected, but you can change the type after taking the applicable restrictions into account.
  7. The new runbook appears 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 a textual runbook.

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 fails 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 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