PowerShell Script Runbook Support in System Center Service Management Automation 2016 (SMA) – Part 1

Update 10/12/2016: This feature is available generally in System Center 2016

Until now, System Center Service Management Automation (SMA) helped you automate your management tasks through runbooks based on PowerShell Workflows. While PowerShell Workflows add a lot of capabilities for PowerShell users (like ability to checkpoint, suspend and resume runbooks and easily parallelizing the execution of runbooks), they come with certain differences to allow for the added capabilities they provide (besides the learning curve associated with Workflows). This basically means that PowerShell Workflows and pure PowerShell scripts are both powerful tools suited for different kinds of jobs. To make both these options available to SMA users, we are happy to announce that System Center Service Management Automation (SMA) 2016 now supports a new runbook type – PowerShell script.

Using PowerShell script runbooks allows you to leverage your PowerShell scripting skills without having to learn PowerShell Workflows while allowing you to author runbooks that start faster than PowerShell Workflow runbooks. You can know more about the differences between two runbook types over here.

This blog will provide a walk-through on creating and running PowerShell script runbooks in SMA. Part 2 will cover using SMA assets in PowerShell runbooks and how to create nested PowerShell runbooks.

You can watch a quick demo of the support for new PowerShell script type runbooks in the above video. For more details, continue reading the blog.

Note: In the examples shown in this post, SMA web service endpoint is assumed to be “https://TAPVMWS” and the working folder is assumed to be “C:\SMA”.

Creating a PowerShell script runbook

A PowerShell (PS) script runbook is a PS script which can be executed against a job schedule. Creating a PowerShell script runbook is as simple as creating a PowerShell script file and then importing and publishing it in SMA as a runbook. The name of the PowerShell script file is used as the runbook name.

Let’s create our first PowerShell script runbook which will run the Get-Date command.

We start by creating PowerShell script file with name SamplePsScriptRunbook_GetDate.ps1. This is a simple one-line script file with a “Get-Date” command.

Once the PowerShell script file is created, we import the file into SMA using the following command:

Import-SmaRunbook -Path C:\sma\SamplePsScriptRunbook_GetDate.ps1 -WebServiceEndpoint https://TAPVMWS -AuthenticationType Windows

At this point, we have created a draft runbook with name SamplePsScriptRunbook_GetDate. Before jobs based on this runbook can be started, the runbook has to be published. Run the following command to publish the runbook:

Publish-SmaRunbook -WebServiceEndpoint https://TAPVMWS -AuthenticationType Windows -Name SamplePsScriptRunbook_GetDate


Running a PowerShell script runbook

Once a PowerShell script runbook is created, jobs based on that runbook can be started. We run the following command to create a job based on the runbook we created earlier:

Start-SmaRunbook -WebServiceEndpoint https://TAPVMWS -AuthenticationType Windows -Name SamplePsScriptRunbook_GetDate

This command creates a job for the runbook and outputs the job ID which could be used to track the status of runbook execution.

To check the status of the job (replace the value for parameter “Id” with the job ID you have got), we run the following command:

Get-SmaJob -WebServiceEndpoint https://TAPVMWS -AuthenticationType Windows -Id ae74d79f-903e-49ff-9db2-b8756f3157e9


You can run the above command multiple times to see the current status of job. Once the job status is “Completed”, you can get the job’s output using the following command (again, replace the value for parameter “Id” with the job ID you have got):

Get-SmaJobOutput -Id ae74d79f-903e-49ff-9db2-b8756f3157e9 -Stream Any -WebServiceEndpoint https://TAPVMWS -AuthenticationType Windows


You can read about all System Center 2016 TP5 features from here and can download Service Management Automation bits from download page.

Please feel free to use the comments section below for any queries or to share your feedback. We look forward to hearing from you.