Status Filer Rules

Already a bit more then a year ago I did a post about Tweeting the deployment status of a system via Orchestrator and ConfigMgr 2012. Sadly enough, the Integration Pack for Orchestrator, that I used in that post, doesn’t work anymore with the most recent Twitter API updates. As I still do get questions and comments about it, I thought it would be a good time to come up with an alternative.

One thing was for sure, it had to be something custom. So easy decision here, PowerShell it is. The next thing is a bit more questionable, how will the script be started… This is the more difficult decision… either run it standalone, via Orchestrator, or via Service Management Automation (SMA). A standalone PowerShell script gives to little control, Orchestrator and PowerShell don’t work that nice together, so the new thing it is, SMA!

The end-result of this post will be a PowerShell workflow, that is triggered form within ConfigMgr. A good thing to keep in mind is that the PowerShell workflow can be triggered from everywhere, with the SMA CmdLets, and is not limited to ConfigMgr!

Service Management Automation (SMA) Runbook

Runbooks in SMA are Windows PowerShell workflows that run on Automation Worker servers. They provide the ability to automate administrative processes for managing and deploying cloud servers, or any other function that a Windows PowerShell script can perform.To configure the Send-Tweet PowerShell workflow, following the next steps:

In the Service Management Portal, navigate to AUTOMATION.

In the automation screen, click RUNBOOKS, click IMPORT and the IMPORT RUNBOOK –popup will show.

On the message Are you sure that you want to save and publish the runbook? Runbook: ‘Send-Tweet’, click YES.

Status Filter Rules

Now let’s end with going to familiar terrain by going to ConfigMgr for configuring the Status Filter Rules. These rules have to perform the tweet action after, either a successful, or a failed deployment of a task sequence. To start the runbook, in SMA, as an action for the Status Filter Rules, use the following configuration:

On the General page fill in as Name<aName> and select the following criteria and click Next.

Select Source and then select Client.

Select Message ID and fill in 11171.

On the Actions page, select Run a program, fill in with ProgramC:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -Command “& {Start-SmaRunbook -WebServiceEndpoint “https://<aWebServiceEndpoint>” -Name “Send-Tweet” -Parameters @{“Message”=’The deployment of %msgsys is succeeded!’}}” and click Next.

On the Summary page, click Next.

On the Completion page, click Close.

This is the configuration of a Status Filter Rule for a successful deployment of a task sequence. To create a Status Filter Rule for a failed deployment repeat the steps from above and replace 11171 with 11170 and replace succeeded with failed.

Result

For my previous blog post I created a twitter account specially for these status messages. From now on this account will show the deployment status of my lab systems again. Some already noticed that this twitter account was active again and this post is the reason of that. Those tweets are done by @MyTaskSequenceS and look like this:

Only a few days before Christmas I thought it would be fun to just create something extra cool for this weeks blog post. I thought about something that would be different, but also useful in some way. So I started thinking about how I would like to get my deployment status messages, as I like to start my deployments without checking them al the time, and I came to Twitter. I’ve got my tweets everywhere, on my phone, my tablet, my laptop, etc. So wouldn’t it be cool to get the deployment status messages on twitter?

Prerequisites

Now I decided that I want to show how to tweet the deployment status of a task sequence, there are two methods to do that and I will show them both. The first method is to use a Status Filter Rule and the second method is to use use the Task Sequence. For these methods, the following points are prerequisites:

The Microsoft Deployment Toolkit 2012 Update 1 –package is created.

The program SCOJobRunner is present on an accessible location for the Site server.

Runbook

Let’s start with configuring the runbook for tweeting the deployment status. To keep this runbook as general as possible, it will need two input parameters. In total this runbook contains two steps with the following configuration:

Add an Initialize Data –activity and double-click it. In the Details Information click Add and a new parameter named Parameter 1 will be added. Now click Parameter 1 and change the name to ComputerName. Repeat that action and rename Parameter 2 to Status, click Ok and click Finish.

Add a Tweet –activity, link it with the previous activity and double-click it. In the Details fill in the field, next to Text, the text to tweet and click Finish. In this example I choose the line @pvanderwoude The deployment of ComputerName is Status!. To get this line in that field, follow the next steps:

Fill in the text “@pvanderwoude The deployment of “.

Right-click and select Subscribe > Published Data. In the Published Data –popup, select with ActivityInitialize Data, select ComputerName and click Ok.

Fill in the text “ is “.

Right-click and select Subscribe > Published Data. In the Published Data –popup, select with ActivityInitialize Data, select Status, and click Ok.

Fill in the text “!“.

Method 1: Status Filter Rules

Now let’s start with the first method, which I also prefer, and that’s configuring the Status Filter Rules. These rules have to perform the tweet action after, either a successful, or a failed deployment of a task sequence. To invoke the runbook as an action for the Status Filter Rules use the following configuration:

On the General page fill in as Name<aName> and select the following criteria and click Next.

Select Source and then select Client.

Select Message ID and fill in 11171.

On the Actions page, select Run a program, fill in with Program<Dir>:\SCOJobRunner.exe -ID:”<aRunbookID>” -Webserver:”<aWebserver>” -Parameters:”ComputerName=%msgsys;Status=succeeded” and click Next.

On the Summary page, click Next.

On the Completion page, click Close.

This was the configuration for a Status Filter Rule with a successful deployment. To create a Status Filter Rule for a failed deployment repeat the steps from above and replace 11171 with 11170 and replace succeeded with failed.

Method 2: Task Sequence

Now let’s go to the second method and that’s configuring the Task Sequence. The task sequence will need some extra logics to see whether it failed or not. This means it needs the following three adjustments

One to set a new variable, OSDDeploymentStatus with a default value of succeeded.

One to change the value of the new variable, OSDDeploymentStatus, to a failed, but only if something in the previous part of the task sequence failed if needed

One to invoke the just created runbook with as input the name of the system and the status of the deployment.

So to put these adjustments together to real configuration changes follow the next six steps:

Add a New Group, fill in <aGroupName> and select in the Options –tab Continue on error.

Add a Set Task Sequence Variable –step, set Task Sequence Variable to OSDDeploymentStatus and set Value to succeeded.

Add a New Group and fill in <aGroupName>.

Add a Set Task Sequence Variable –step, set Task Sequence Variable to OSDDeploymentStatus and set Value to failed. Then go to the Options –tab and click Add Condition > Task Sequence Variable. In the Task Sequence Variable –popup, fill in as Variable_SMSTSLastActionSucceeded, set as Conditionequals, fill in as ValueFalse and click Ok.

Add and Execute Runbook –step, fill in with Orchestrator Server<anOrchestratorServer> and Browse with Runbook to the just created runbook. Then select Specify explicit runbook parameters, fill in with ComputerName %_SMSTSMachineName%, fill in with Status %OSDDeploymentStatus% and select Wait for the runbook to finish before continuing.

Result

As always, after all the configuring, it’s time to look at the results. Normally I like to show log files, or screenshots from console, or screenshots from the event viewer, but this time it’s time for something different. Specially for this post I created a new twitter account that, from now on, will show the deployment status of my lab systems. Those tweets are done by @MyTaskSequenceS and look like this:

The last couple of weeks I’ve done some posts about using Orchestrator in combination with ConfigMgr 2012. This week I’ve got another one and it’s also another method to invoke a runbook. Until now I’ve used, either Runbook Commander to create right-click actions, or the Execute Runbook –step from MDT 2012 to start an action during a task sequence. This week I’m going to use SCOJobRunner – Command Line Utility, by Robert Hearn, to invoke a runbook as an action for a Status Filter Rule. SCOJobRunner can be used to, either invoke a runbook, or get the parameters of a runbook. For a good informational post about SCOJobRunner take a look at this post of Robert Hearn himself.

Prerequisites

In this post I want to show how to invoke a runbook as an action for a Status Filter Rule by creating a basic runbook for deleting a direct collection membership rule. I know Jörgen Nilsson already did a similar runbook and executed it during a task sequence, but in this case it’s about showing possibilities and not about showing fancy runbooks. For the rest of this post the following points are prerequisites:

SCOJobRunner needs to be present on an accessible location for the Site server.

Runbook

Let’s start with configuring the runbook for deleting the direct collection membership. This runbook contain two steps with the following configuration:

Add an Initialize Data –activity and double-click it. In the Details Information click Add and a new parameter named Parameter 1 will be added. Now click Parameter 1 and change the name to ComputerName. Repeat that action and rename Parameter 2 to CollectionName, click Ok and click Finish.

Add a Delete Collection Rule –activity, link it with the previous activity and double-click it. In the Details perform the following actions and click Finish.

Right-click the field next to Collection and select Subscribe > Published Data. In the Published Data –popup, select with ActivityInitialize Data, select CollectionName and click Ok.

Click with the field next to Collection Value Type on … and then select in the Item Selection –popup Name and click Ok.

Right-click the field next to Membership Rule and select Subscribe > Published Data. In the Published Data –popup, select with ActivityInitialize Data, select ComputerName, and click Ok.

Click with the field next to Membership Rule Type on … and then select in the Item Selection –popup Direct Rule and click Ok.

Status Filter Rule

Now let’s start with the, coolest part, configuring the Status Filter Rule. This rule has to perform the delete collection membership action after a successful deployment of a specific task sequence. To invoke the runbook as an action for a Status Filter Rule use the following configuration:

On the General page fill in as Name<aName> and select the following criteria and click Next.

Select Source and then select Client.

Select Message ID and fill in 11171.

Select Property and then select Package ID.

Select Property Value and then select <aTaskSequenceId>.

On the Actions page select the following actions and click Next.

Select Report to the event log.

Select Run a program and fill in with Program<Dir>:\SCOJobRunner.exe -ID:”<aRunbookID>” -Webserver:”<aWebserver>” -Parameters:”ComputerName=%msgsys;CollectionName=<aCollectionName>”.

Note: The idea here is to match aTaskSequenceId with aCollectionName.

On the Summary page, click Next.

On the Completion page, click Close.

Result

As always, now it’s time to look at the results and like all other times there are lot’s of places to look at. This time I won’t show any log files, but “just” the successful results from the actions of the Status Filter Rule. I configured the rule to perform two actions. The first action is to report to the event log (see first picture) and the second action is to invoke a runbook (see second picture).

Award

Subscribe to updates

About

I’m Peter van der Woude, born in 1983 and I’m living together with my wife and two sons in the Netherlands.

Currently I work for KPN Consulting. At this moment my main focus is Enterprise Client Management via Microsoft Intune and/ or System Center Configuration Manager (ConfigMgr 2007/ 2012/ CB) and I love it!