title | description | services | documentationcenter | author | manager | editor | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Editing textual runbooks in Azure Automation |
This article provides different procedures for working with PowerShell and PowerShell Workflow runbooks in Azure Automation using the textual editor. |
automation |
eslesar |
stevenka |
tysonn |
6f5b48fb-6f30-4e99-9e14-9061b5554b08 |
automation |
na |
article |
na |
infrastructure-services |
02/23/2016 |
magoedte;bwren |
The textual editor in Azure Automation can be used to edit PowerShell runbooks and PowerShell Workflow runbooks. This has the typical features of other code editors such as intellisense and color coding with additional special features to assist you in accessing resources common to runbooks. This article provides detailed steps for performing different functions with this editor.
The textual editor includes a feature to insert code for activities, assets, and child runbooks into a runbook. Rather than typing in the code yourself, you can select from a list of available resources and have the appropriate code inserted into the runbook.
Each runbook in Azure Automation has two versions, Draft and Published. You edit the Draft version of the runbook and then publish it so it can be executed. The Published version cannot be edited. See Publishing a runbook for more information.
To work with Graphical Runbooks, see Graphical authoring in Azure Automation.
Use the following procedure to open a runbook for editing in the textual editor.
- In the Azure portal, select your automation account.
- Click the Runbooks tile to open the list of runbooks.
- Click the name of the runbook you want to edit and then click the Edit button.
- Perform the required editing.
- Click Save when your edits are complete.
- Click Publish if you want the latest draft version of the runbook to be published.
- In the Canvas of the textual editor, position the cursor where you want to place the cmdlet.
- Expand the Cmdlets node in the Library control.
- Expand the module containing the cmdlet you want to use.
- Right click the cmdlet to insert and select Add to canvas. If the cmdlet has more than one parameter set, then the default set will be added. You can also expand the cmdlet to select a different parameter set.
- The code for the cmdlet is inserted with its entire list of parameters.
- Provide an appropriate value in place of the data type surrounded by braces <> for any required parameters. Remove any parameters you don't need.
- In the Canvas of the textual editor, position the cursor where you want to place the code for the child runbook.
- Expand the Runbooks node in the Library control.
- Right click the runbook to insert and select Add to canvas.
- The code for the child runbook is inserted with any placeholders for any runbook parameters.
- Replace the placeholders with appropriate values for each parameter.
- In the Canvas of the textual editor, position the cursor where you want to place the code for the child runbook.
- Expand the Assets node in the Library control.
- Expand the node for the type of asset you want.
- Right click the asset to insert and select Add to canvas. For variable assets, select either Add "Get Variable" to canvas or Add "Set Variable" to canvas depending on whether you want to get or set the variable.
- The code for the asset is inserted into the runbook.
Use the following procedure to open a runbook for editing in the textual editor.
- In the Azure portal, select Automation and then then click the name of an automation account.
- Select the Runbooks tab.
- Click the name of the runbook you want to edit and then select the Author tab.
- Click the Edit button at the bottom of the screen.
- Perform the required editing.
- Click Save when your edits are complete.
- Click Publish if you want the latest draft version of the runbook to be published.
- In the Canvas of the textual editor, position the cursor where you want to place the activity.
- At the bottom of the screen, click Insert and then Activity.
- In the Integration Module column, select the module that contains the activity.
- In the Activity pane, select an activity.
- In the Description column, note the description of the activity. Optionally, you can click View detailed help to launch help for the activity in the browser.
- Click the right arrow. If the activity has parameters, they will be listed for your information.
- Click the check button. Code to run the activity will be inserted into the runbook.
- If the activity requires parameters, provide an appropriate value in place of the data type surrounded by braces <>.
- In the Canvas of the textual editor, position the cursor where you want to place the child runbook.
- At the bottom of the screen, click Insert and then Runbook.
- Select the runbook to insert from the center column and click the right arrow.
- If the runbook has parameters, they will be listed for your information.
- Click the check button. Code to run the selected runbook will be inserted into the current runbook.
- If the runbook requires parameters, provide an appropriate value in place of the data type surrounded by braces <>.
- In the Canvas of the textual editor, position the cursor where you want to place the activity to retrieve the asset.
- At the bottom of the screen, click Insert and then Setting.
- In the Setting Action column, select the action that you want.
- Select from the available assets in the center column.
- Click the check button. Code to get or set the asset will be inserted into the runbook.
To edit a runbook with Windows PowerShell, you use the editor of your choice and save it to a .ps1 file. You can use the Get-AzureAutomationRunbookDefinition cmdlet to retrieve the contents of the runbook and then Set-AzureAutomationRunbookDefinition cmdlet to replace the existing draft runbook with the modified one.
The following sample commands show how to retrieve the script for a runbook and save it to a script file. In this example, the Draft version is retrieved. It is also possible to retrieve the Published version of the runbook although this version cannot be changed.
$automationAccountName = "MyAutomationAccount"
$runbookName = "Sample-TestRunbook"
$scriptPath = "c:\runbooks\Sample-TestRunbook.ps1"
$runbookDefinition = Get-AzureAutomationRunbookDefinition -AutomationAccountName $automationAccountName -Name $runbookName -Slot Draft
$runbookContent = $runbookDefinition.Content
Out-File -InputObject $runbookContent -FilePath $scriptPath
The following sample commands show how to replace the existing contents of a runbook with the contents of a script file. Note that this is the same sample procedure as in To import a runbook from a script file with Windows PowerShell.
$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