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 Classic portal
You can only work with PowerShell Workflow runbooks in the Azure portal.
- In the Azure Classic portal, click, New, App Services, Automation, Runbook, Quick Create.
- Enter the required information, and then click Create. The runbook name must start with a letter and can have letters, numbers, underscores, and dashes.
- If you want to edit the runbook now, then click Edit Runbook. Otherwise, click OK.
- Your new runbook will appear on the Runbooks tab.
To create a new Azure Automation runbook with the Azure portal
- In the Azure portal, open your Automation account.
- Click on the Runbooks tile 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.
To create a new Azure Automation runbook with Windows PowerShell
You can use the New-AzureAutomationRunbook 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 script file.
The following sample commands show how to create a new empty runbook.
$automationAccountName = "MyAutomationAccount" $runbookName = "Sample-TestRunbook" New-AzureAutomationRunbook –AutomationAccountName $automationAccountName –Name $runbookName
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.
- In the Azure Management portal, select Automation and then select an Automation Account.
- Click Import.
- Click Browse for File and locate the script file to import.
- If you want to edit the runbook now, then click Edit Runbook. Otherwise, click OK.
- The new runbook will appear on the Runbooks tab for the Automation Account.
- 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 that you can import a .ps1 file into a PowerShell runbook or a PowerShell Workflow runbook using this portal.
- In the Azure portal, open your Automation account.
- Click on the Runbooks tile 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.
- Select a runbook type taking into account the restrictions listed above.
- The new runbook will appear in the list of runbooks for the Automation Account.
- You must publish the runbook before you can run it.
To import a runbook from a script file with Windows PowerShell
You can use the Set-AzureAutomationRunbookDefinition cmdlet to import a script file into the Draft version of an existing runbook. The script file must contain a single Windows PowerShell Workflow. If the runbook already has a Draft version, then the import will fail unless you use the Overwrite parameter. After the runbook has been imported, you can publish it with Publish-AzureAutomationRunbook.
The following sample commands show how to import a script file into an existing runbook and then publish it.
$automationAccountName = "MyAutomationAccount" $runbookName = "Sample-TestRunbook" $scriptPath = "c:\runbooks\Sample-TestRunbook.ps1" Set-AzureAutomationRunbookDefinition –AutomationAccountName $automationAccountName –Name $runbookName –Path $ scriptPath -Overwrite Publish-AzureAutomationRunbook –AutomationAccountName $automationAccountName –Name $runbookName
Publishing a runbook
When you create or import a new runbook, you must publish it before you can run it. Each runbook in Azure 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
- Open the runbook in the Azure Classic portal.
- At the top of the screen, click Author.
- At the bottom of the screen, click Publish and then Yes to the verification message.
To publish a runbook using the Azure portal
- Open the runbook in the Azure portal.
- Click the Edit button.
- Click the Publish button and then Yes to the verification message.
To publish a runbook using Windows PowerShell
You can use the Publish-AzureAutomationRunbook cmdlet to publish a runbook with Windows PowerShell. The following sample commands show how to publish a sample runbook.
$automationAccountName = "MyAutomationAccount" $runbookName = "Sample-TestRunbook" Publish-AzureAutomationRunbook –AutomationAccountName $automationAccountName –Name $runbookName