Using Service Management Automation (SMA) for tweeting status messages of ConfigMgr 2012

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!

For those not familiar with SMA, yet, see: http://technet.microsoft.com/en-us/library/dn469258.aspx

Prerequisites

Now I decided how I want to start the tweets, it’s time to take a look at the following prerequisites:

  • Create a Twitter application with an Access level of at least Read and Write. This allows an application to perform read and write actions on this twitter account.
  • Install System Center 2012 R2 Service Management Automation PowerShell on the ConfigMgr server. This enables the ConfigMgr server to run the SMA CmdLets.
  • Download the Send-Tweet.ps1 PowerShell workflow script. The main component of this script is created thanks to this great post of Ian Chevers. I updated his script to work with the Twitter API version 1.1 and to run within a PowerShell workflow.

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.
  • Browse to Send-Tweet.ps1 and click Open, followed by clicking the .
  • Back in the automation screen, click RUNBOOKS and select Send-Tweet.
  • Send-TweetIn the send-tweet screen, click AUTHOR, click DRAFT and click PUBLISH.
  • 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. SFR_DeploymentGeneralTo start the runbook, in SMA, as an action for the Status Filter Rules, use the following configuration:

  • In the Configuration Manager Console, navigate to Administration > Overview > Site Configuration > Sites.
  • In the Home tab click Settings > Status Filter Rules, click Create and the Create Status Filter Rule Wizard will show.
  • 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.
  • SFR_DeploymentActionsOn the Actions page, select Run a program, fill in with Program C:\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:

Tweets

Share

Tweeting the deployment status of a system via Orchestrator and ConfigMgr 2012

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.
  • The Site server is member of the OrchestratorUser –group.
  • The Network Access Account is member of OrchestratorUser –group.
  • The Social Media Integration Pack, of VIAcode, is registered, deployed and configured.

Runbook

OrcRunBooTweLet’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:

  • OrcRunBooIniDatDetAdd 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. OrcRunBooTweProIn 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 Activity Initialize 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 Activity Initialize 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. StaFilRulTweGenTo invoke the runbook as an action for the Status Filter Rules use the following configuration:

  • In the Configuration Manager Console, navigate to Administration > Overview > Site Configuration > Sites.
  • In the Home tab click Settings > Status Filter Rules, click Create and the Create Status Filter Rule Wizard will show.
  • 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.
  • StaFilRulTweActOn 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

  1. One to set a new variable, OSDDeploymentStatus with a default value of succeeded.
  2. 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
  3. One to invoke the just created runbook with as input the name of the system and the status of the deployment.

TSEdiTweSta01So 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>.
  • TSEdiTweSta02Add 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 Condition equals, fill in as Value False and click Ok.
  • Add an Use Microsoft Deployment Toolkit Package –step and Browse to the Microsoft Deployment Toolkit 2012 Update 1 –package.
  • TSEdiTweSta03Add 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:

TasSeqStaTwe

Share

Using a Status Filter Rule to delete a collection membership via Orchestrator and ConfigMgr 2012

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:

Runbook

OrgRunBooDelColRulLet’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 Activity Initialize 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 Activity Initialize 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:

  • StaFilRulProGenIn the Configuration Manager Console, navigate to Administration > Overview > Site Configuration > Sites.
  • In the Home tab click Settings > Status Filter Rules, click Create and the Create Status Filter Rule Wizard will show.
  • 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>.
  • StaFilRulProActOn 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).EveVieStaFilMesOrcRunBooRes

Share