Some additional information in one line

Step by step instructions on sending messages to Microsoft Teams from MOVEit Automation

Technical top tips for MOVEit MFT

In this technical top tip, our MOVEit expert Richard Auger explains how to send messages to Microsoft Teams from MOVEit Automation.

A while ago I wrote a small script for MOVEit Automation that allowed me to send messages to Slack from an Automation task.  Over the recent months it’s become evident that while this is a useful function for alerting, more organisations are moving towards Microsoft Teams for this kind of activity.

This article describes how you can implement an alerting mechanism to send alerts to Teams in the event of a task failure (or success, if you prefer).  You should note however that you should not use Teams as a logging tool as this goes against EULA conditions.

To start with, you need to create a channel within Teams that you can send messages to.  To do this, open Teams, select ‘Teams’ and highlight a team that you have access to manage.  From the context menu, click ‘add channel’.  Give the channel a name (mine is called ‘powershell’) and set the permissions to allow members to add connectors.

Richards Team

Next, select the channel and from the context menu, click connectors

Richards Team

You’ll see a list of connectors, select ‘incoming webhook’ and configure it.  This will result in a webhook URL being displayed – copy this into a text file for safe keeping, you’ll need it later.

Connectors for Powershell Channel in Richards Team
Now go to MOVEit Automation and click on resources – scripts.  Click on ‘Add Script’.  I’m using Powershell for this, but if you prefer to write your own you could use VB.  Paste the following code into the script.  Replace the xxxx with your URL that you received when creating the Teams channel connector:

$ErrorCodeTask = $miaclient.MIGetTaskParam(“MyError”)

$ErrorDescriptionTask = $miaclient.MIGetTaskParam(“MyDescription”)

$TaskName = $miaclient.MIGetTaskParam(“MyTask”)

 

$JSON = @{

“@type”      = “MessageCard”

“@context”   = “http://schema.org/extensions”

“title”      = “$TaskName Completed with Return code $ErrorCodeTask”

“text”       = “$TaskName has failed with Error: $ErrorDescriptionTask”

}

$JSON = ConvertTo-Json $JSON

 

$uri = “xxxx

$ContentType= ‘application/json’

Invoke-RestMethod -uri $uri -Method Post -body $JSON -ContentType $ContentType

The end result should look something like this:

Teams

You’ll notice that there are three parameters being passed into the script.  These can be set to use macros related to the current task (ErrorCodeTask, ErrorDescriptionTask and TaskName), or you can choose to have the Teams call in a task of it’s own that you can call from any task, in which case simply pass these values as parameters. 

You can of course expand the descriptive text in any way that you like

Edit Task Parameters

Finally, the message in Teams will appear like this:

Powershell

I should mention that this script requires that your Automation is licenced for custom scripts; if it isn’t, you will have to create the powershell as an external script and call it from the command line app by executing powershell as the program and passing the script and parameters as command line app parameters instead.  It will still work in the same way, however.

Need UK-based MOVEit support?

We are certified Progress MOVEit Titanium Partners and our team includes the UK’s leading MOVEit expert.
See our range of support and consultancy services to help you get the most out of your MOVEit solution.