SCSM – Apply SMA Runbook Template Using SMA / PowerShell

In my previous post I have written about adding activities to a service request using PowerShell SMLets. Well this just added the “empty” activities / “framework” but the activities were not configured yet.

As an example I want to add a SMA runbook activity (using this method) and then apply a pre-configured SMA runbook template in SCSM. This template has all the configuration  defined like the connection settings / credentials, the SMA runbook to start, parameters to pass to the SMA runbook etc.

Lee Berg has provided a very detailed post about how you would apply a service request template to a service request. I used his principle to do the same for a SMA runbook activity. Cireson provides so far the only SMA connector for Service Manager and because of that this example is built on that product.

As a starting point I have a service request with a review activity, a manual activity and a parallel activity…

image

I run the script from my previous post and this adds a sequential activity with a review and a SMA runbook activity (RB2962)…

image

I previously created a SMA Runbook Activity Template called “SMAT – SOL000004 – Pre Order Device”. The General section looks like this…

image

…and the Runbook section like this…

image

My goal is to apply this template to the RB2962 activity using PowerShell SMlets. I created a Apply-SMARBTemplateToSMARBActivity workflow which looks like this…

image

I pass the SMA runbook activity id and also the SMA runbook template display name as parameter to the script. Next, I get the SMA assets for the SCSM server (FQDN) and the credentials which have access on Service Manager. Then I use InlineScript to execute the PowerShell code on the Service Manager management server itself which has the SMlets installed.

Now it get’s dirty :). First, we get the type projection System.WorkItem.Activity.SMARunbookActivityProjection . What a type projection is, is well described here, but somewhat still hard to understand :). Then we get the runbook projection object itself (Get-SCSMObjectProjection), query Service Manager for the SMA runbook template (Get-SCSMObjectTemplate) by display name and finally we “glue” / set everything together using Set-SCSMObjectTemplate.

How does it look in action? If we start the workflow in SMA, enter the runbook id and also the SMA runbook template display name…

image

…after it ran successfully we see that the activity changed…

image

…and also the connection settings, parameter etc. got applied to the activity from the template…

image

I just stripped down the code to provide a simple example how you could do it using SMA / PowerShell workflow. There might be other ways, if so, let me know :).

I hope this provides a good starting point.

You can find the script here on TechNet Gallery

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s