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 |
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.
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.
- In the Azure portal, open your Automation account.
- From the Hub, select Runbooks to open the list of runbooks.
- Click on the Add a runbook button and then Create a new runbook.
- 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.
- Click Create to create the runbook and open the editor.
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
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.
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.
- In the Azure portal, open your Automation account.
- From the Hub, select Runbooks to open the list of runbooks.
- Click on the Add a runbook button and then Import.
- Click Runbook file to select the file to import
- 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.
- The runbook type is automatically selected, but you can change the type after taking the applicable restrictions into account.
- The new runbook appears in the list of runbooks for the Automation Account.
- 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.
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
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.
- Open the runbook in the Azure portal.
- Click the Edit button.
- Click the Publish button and then Yes to the verification message.
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
- To learn about how you can benefit from the Runbook and PowerShell Module Gallery, see Runbook and module galleries for Azure Automation
- To learn more about editing PowerShell and PowerShell Workflow runbooks with a textual editor, see Editing textual runbooks in Azure Automation
- To learn more about Graphical runbook authoring, see Graphical authoring in Azure Automation