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

Leave a Comment