Sending Notifications to Teams from WhereScape RED

Jan 7, 2022 Uncategorized

In our Video, we discuss : How to Send Your Scheduler Notifications to Microsoft Teams using a WebHook via PowerShell.

Find out more here:

Here is an example of the code used to send a notification:

param ($SequenceNumber, $NotificationMessage)

$IncidentStartTime = Get-Date -Format "dddd dd/MM/yyyy HH:mm"
$IncidentServiceName = "P & L Server"
$IncidentMessage = $NotificationMessage

[string]$username = Get-Content C:\Temp\user.txt
[SecureString]$securePwd = Get-Content C:\Temp\password.txt | ConvertTo-SecureString -Key (Get-Content C:\Temp\aes.key) 
$psCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$username", $securePwd

$adminURL = Get-Content C:\Temp\TenantURL.txt
$siteURL = Get-Content C:\Temp\TeamURL.txt 

[string]$webhookURL = Get-Content C:\Temp\WebhookURL.txt

Connect-PnPOnline -Url $adminURL  -Credentials $psCred

[string]$Notification = @"
    {
        "@type": "MessageCard",
        "@context": "https://schema.org/extensions",
        "summary": "Data Warehouse Notification",
        "themeColor": "0072C6",
        "title": "Data Warehouse Notification",
         "sections": [{
            
                "facts": [
                    {
                        "name": "Job Sequence:",
                        "value": "SequenceNumber"
                    },
                    {
                        "name": "Date/Time:",
                        "value": "DATETIME"
                    },
                    {
                        "name": "Job Name:",
                        "value": "SERVICENAME"
                    },
                    {
                        "name": "Description:",
                        "value": "MESSAGE"
                    },
                    {
                        "name": "HTML Table:",
                        "value": "MESSAG1"
                    }]  
                    ,"text": "Data Warehouse Notification Update"
                
            }]
    }
"@

#Create Variables to insert values into the JSON payload.

[string]$NotificationBody = $Notification.Replace("SequenceNumber","$SequenceNumber").Replace("DATETIME","$IncidentStartTime").Replace("SERVICENAME","$IncidentServiceName").Replace("MESSAGE","$IncidentMessage").Replace("MESSAG1","$HTMLRowData")

Invoke-RestMethod -Uri $webhookURL -Method Post -Body $NotificationBody -ContentType 'application/json'

We would love to hear how you have used or adapted the code for your own purposes!

Contact Us


Call us on:

(+44) 0204 566 5056

Send a message:

Here