Editing a Runbook
Updated: May 13, 2016
Applies To: Windows Azure Pack for Windows Server
Each runbook in Service Management Automation has two versions, Draft and Published. You edit the Draft version of the workflow and then publish it so it can be executed. The Published version cannot be edited.
To Edit a Runbook with the Management Portal
The Management Portal includes an editor that you can use to view and edit runbooks. In addition to providing basic text editing capabilities, the editor provides the ability to automatically insert code for Global Assets, Activities, and Runbooks.
In the Management Portal, select Automation.
Select the Runbooks tab.
Click the name of the runbook you want to edit.
Select the Author tab.
Either click Draft at the top of the screen or 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.
Inserting Code into a Runbook
The Automation editor includes a feature to insert code for Activities, Settings and Runbooks into a runbook. Rather than typing in the code yourself, you can select from a list of available assets and have the appropriate code inserted into the runbook.
To Insert Code for a Runbook into a Runbook
Open the runbook in the Management Portal editor.
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 <>.
To Insert a Global Asset into a Runbook
Open the runbook in the Management Portal editor.
At the bottom of the screen, click Insert and then Setting.
In the Setting Action column, select the type of code that you require
Select from the available assets in the center column.
Click the check button.
To Insert an Activity into a Runbook
Open the runbook in the Management Portal editor.
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 <>.
To Edit an Automation Runbook Using Windows PowerShell
To edit a runbook with Windows PowerShell, you edit the workflow using the editor of your choice and save it to a .ps1 file. You can use the Get-SMARunbookDefinition cmdlet to retrieve the contents of the runbook and then Edit-SMARunbook cmdlet to replace the existing draft workflow with the modified one.
To create a new runbook from the contents of a script file, see To import a runbook from a script file with Windows PowerShell.
To Retrieve the Contents of a Runbook Using Windows PowerShell
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.
$webServer = 'https://MyServer'
$port = 9090
$runbookName = "Test-Runbook"
$scriptPath = "c:\runbooks\Test-Runbook.ps1"
$runbookDefinition = Get-SMARunbookDefinition –WebServiceEndpoint $webServer –Port $port -Name $runbookName -Type Draft
$runbookContent = $runbookDefinition.Content
Out-File -InputObject $runbookContent -FilePath $scriptPath
To Change the Contents of a Runbook Using Windows PowerShell
The following sample commands show how to replace the existing contents of a runbook with the contents of a script file containing a workflow.
$webServer = 'https://MyServer'
$port = 9090
$runbookName = "Test-Runbook"
$scriptPath = "c:\runbooks\Test-Runbook.ps1"
Edit-SmaRunbook –WebServiceEndpoint $webServer –Port $port -Name $runbookName -Path $scriptPath -Overwrite
Publish-SmaRunbook –WebServiceEndpoint $webServer –Port $port –Name $runbookName –Path $scriptPath
See Also
Creating or Importing a Runbook
Service Management Automation
Runbook Authoring [SMA]