Configuration Management Pack Script

SCOM 2012 – Meets MS Flow and Service Bus or How to Translate Alerts


Everything is going international and everything is interconnected. Microsoft is providing many technologies to build bridges between different technologies and systems. I like the idea to build connectors to have a system A talking to system B within a matter of seconds. Microsoft Flow is such a technology which will interconnect systems with each other. Although the idea behind Microsoft Flow is not new, there are other providers like IFTTT or Zapier which are much longer on the market. The differences lie in connecting to endpoints, transforming data and sending to a target. Depending on your needs you will use one or the other or you might want to interconnect one task automation engine with the other. gives a short comparison:

  • IFTTT: IFTTT is super easy to use. As the name suggests, you set up a trigger: that’s the “if.” Then you pick a reaction, that’s the “that.” IFTTT supports 320 popular services, including Dropbox, Drive, WordPress, Twitter, and plenty of others. IFTTT calls these “recipes,” and you can browse recipes made by other people, which makes it easy to come up with ideas for how you can use the service on your own. On top of the web site, IFTTT also has Android and iOS apps so you can take the experience on the go. IFTTT is free. On Android, IFTTT and Tasker work very similarly.
  • Zapier: Zapier works just like IFTTT, but instead of “recipes” the service calls your actions “zaps.” Zapier focuses more on business app integration, so it supports niche corporate apps, like Recurly, HelloSign, and MySQL. Zapier is also more customizable. Where IFTTT limits itself to two steps (this happens, then that happens), Zapier supports multi-step zaps (this happens, then that, that, and that). That said, Zapier doesn’t have mobile apps. It’s also not free. While Zapier has a free plan, it limits you to five zaps at once, locks off access to certain apps, and can only make two-step zaps (just like IFTTT). For $20/month, you unlock Zapier’s real power, including access to all 500+ app integrations and multi-step zaps.
  • Microsoft Flow: Flow is the newest automation tool on the block and it’s the most limited. As you’d expect, Flow’s strength is its integration with Microsoft apps and services. Flow works like IFTTT, with two-step automation recipes called “templates.” Also like IFTTT, you can browse other people’s templates or share your own. Currently, Flow is a “preview” build on the web, which aside from being a bit limited in scope, also limits it to work or school email accounts. Chances are, that doesn’t include you, unless your company is deep in the Microsoft ecosystem or you’re a student. But hey, at least there’s also an iPhone version. For now, Flow is free as long as it’s in preview.

In our example I will use Microsoft Azure Service Bus, PowerShell, Microsoft Flow, Office 365 to help my old friend SCOM to translate alerts in many languages. Sounds cool? Yes it really is!

First we need to setup Microsoft Azure Service Bus Queue. So what is Service Bus (Source)?

Service Bus is a multi-tenant cloud service, which means that the service is shared by multiple users. Each user, such as an application developer, creates a namespace, then defines the communication mechanisms she needs within that namespace. shows how this looks.


Within a namespace, you can use one or more instances of four different communication mechanisms, each of which connects applications in a different way. The choices are:

  • Queues, which allow one-directional communication. Each queue acts as an intermediary (sometimes called a broker) that stores sent messages until they are received. Each message is received by a single recipient.
  • Topics, which provide one-directional communication using subscriptions-a single topic can have multiple subscriptions. Like a queue, a topic acts as a broker, but each subscription can optionally use a filter to receive only messages that match specific criteria.
  • Relays, which provide bi-directional communication. Unlike queues and topics, a relay doesn’t store in-flight messages-it’s not a broker. Instead, it just passes them on to the destination application.
  • Event Hubs, which provide event and telemetry ingress to the cloud at massive scale, with low latency and high reliability.

As you can see a queue is the simplest part to use in Service Bus, it reminds me a bit like a printer queue, instead of sending documents, you are able to send messages. Ok so let’s install a queue…

Service Bus Queue

Got to the classic Azure portal and go to Service Bus


…and click Create


Then provide a name for your namespace, in my case I have choosen returnone, configure the type which is Messaging for our Queue and the Messaging Tier I choose Standard. If you want to know the differences go here. And finally choose the region, the closest place to your other resources. In my case West Europe.

Your namespace should be visible…


…select the Queue and create a new Queue


…choose Quick Create


…now your Queue will be visible…


Next click on to the Queue and choose Configure. Provide a policy name like scom and choose the permissions Send and Listen. We use both permissions, because we need this policy to listen and send messages to Service Bus. Hit Save and now you should see an output like this…


…go to the Dashboard and click Connection Information right on the bottom of the console. You will be prompted with a dialog which shows you a connection string, that we will use in the next steps…


That’s it we have configured Service Bus and a Queue. Next we will configure Microsoft Flow.

Microsoft Flow

Go to and register and login with your account. Microsoft Flow is currently in preview phase and therefore for free. Select My flows and click Create new flow. Choose Service Bus – When a message is received in queue


Next enter a connection name and the connection string…


The connection string you get when you configure the Service Bus it looks like this

SharedAccessKeyName=[Your AccessKeyName];

Remove the “EntityPath=blabla” part of the connection string. It is not needed, and the Flow would not work! It throws an error like this…


Next add the next activity Translate Text. This will use Microsoft Translator, where you might first want to login and create an account. See for more details and sign-up. Create a connection, in my case I already have a connection, it looks a bit different, when you create a new connection…


I tried to create a second, new connection, but for some reason I ran into an error. If you are starting from scratch you should be able to create the connection seamlessly…


If you managed to setup the connection, add in the Text section the Content data from the previous activity and also select a Target language, in my case German….


As final activity we will use Send email. Just add it and configure it, it is pretty self explaining. In the screenshot, we us the To property from the Service Bus message for the recipient of the mail, for this demo the subject is just static and the Body of the will be the translated text…


Next save this flow as DEMO


Your flow is now visible und should look like this…


As a next step we need to create a PowerShell script and configure the Command Notification Channel in SCOM for executing the script and sending the alert data to Service Bus. I will try to explain each part of the script…

PowerShell Script

There are three string parameters, one for the alert name, one for the alert description and one for the mail recipient.


Next we import the Service Bus and the OperationsManager module…


Because we need to connect to Service Bus, we need the connection string which is stored in a RunAs account in SCOM. See this post about more details…


Next, we create just the alert message string and limit the characters to 250 characters length. If you want to have all data sent, just uncomment the line…


Here we create a client instance of the for Service Bus and pass the connection string…


This is the tricky part. Because Service Bus usually wraps the message content in XML, it won’t be useful for us. We just want to have the plain text, therefore we “cheat” on the Service Bus API and send the message string in UTF8 characters. This will tell the API that we handle the string. Then we create a memory stream object…


Next, we create the Service Bus message object, pass the memory stream, assign a GUID to the message id, add the message recipient address and add some properties (just for demo)…


Finally we trigger the send method…


You can download the script from TechNet Gallery, here. The Service Bus DLL is available here on nuget .

Next we will embed the script into the Command Notification Channel in SCOM.

Command Notification Channel

Well I am not going into details how to configure a Command Notification Channel, there are plenty of posts on the internet like this here, that explains very well how to do it.

I saved the script above as Send-SBMessage40.ps1 in C:\Temp on my management server and copied also the Microsoft.ServiceBus.dll into the same directory…


The Command Notification Channel configuration looks like this…


Full path of the command file:


Command line parameters (Note: make sure you change the mail address)

-Command “& ‘”C:\temp\Send-SBMessage40.ps1″‘” ‘$Data[Default=’Not Present’]/Context/DataItem/AlertName$’ ‘$Data[Default=’Not Present’]/Context/DataItem/AlertDescription$’ ‘’

Startup folder for the command line:


After configuration you will have the channel available…


Next assign this channel to a Subscription which is also very well explained in this article.

That’s the entire procedure now you just need to trigger an alert :). I configured my subscription to fire on any alert on any status. This means I just can change the status from Closed to New and the channel will fire. So a sample alert…


… will end up in German like this…


It is kind of fun to see the translation which not always matches the in a perfect sense :D. But you might want to try some foreign languages. Be aware of the fact, that Service Bus and especially Microsoft Translator as some limits. Before you start to use MS Translator you should know that the Free trial is limited to  2’000’000  characters per month somehow I managed to reach this limit…


I hope you get this thing going and you have as much fun as I have!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.