Use Webhook Connector to send data from PowerShell to Microsoft Teams

Yesterday we announced Microsoft Teams, a new chat-based workspace in Office 365. Microsoft Teams is an entirely new experience that brings together people, conversations and content—along with the tools that teams need—so they can easily collaborate to achieve more.

Check this video or the step-by-step introduction video to learn more.

One of the cool features is the connectors you can use with Microsoft Teams. Office 365 Connectors are a great way to get useful information and content into Microsoft Teams. Any user can connect their team to services like Trello, GitHub, Bing News, Twitter, etc., and get notified of the team's activity in that service

image

Scroll through the Connectors and select the Incoming Webhook Connector

 

image

 

Give your Incoming Webhook Connector a name and upload an fitting icon and click create.

image

 

Copy the Incoming Webhook url to your clipboard, we will need that info in our PowerShell script.

image

 

PowerShell script

We now are going to call the Incoming Webhook from PowerShell.

 [sourcecode language='powershell'  padlinenumbers='true']
# ---------------------------------------------------
# Script: C:\Users\stefstr\Microsoft\OneDrive - Microsoft\Scripts\PS\MicrosoftTeams\testwebhook_v2.ps1
# Version: 0.1
# Author: Stefan Stranger
# Date: 11/03/2016 10:48:58
# Description: Call Microsoft Teams Incoming Webhook from PowerShell
# Comments:
# Changes:  
# Disclaimer: 
# This example is provided “AS IS” with no warranty expressed or implied. Run at your own risk. 
# **Always test in your lab first**  Do this at your own risk!! 
# The author will not be held responsible for any damage you incur when making these changes!
# ---------------------------------------------------


$webhook = '[webhookurl]'

$Body = @{
        'text'= 'Hello World! from PowerShell'
}

$params = @{
    Headers = @{'accept'='application/json'}
    Body = $Body | convertto-json
    Method = 'Post'
    URI = $webhook 
}

Invoke-RestMethod @params

If everything works ok, this will be the result.

msteamswebhook

Have fun using Microsoft Teams!