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


Scroll through the Connectors and select the Incoming Webhook Connector




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



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



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.


Have fun using Microsoft Teams!

Comments (22)
  1. Joe says:

    Glad to see Teams released! Having some challenges with WebHooks. When I try to create one from my on-prem TFS 2015 (“build has completed” event), with the URL provided by Teams, my test results in a HTTP 400 error. When I use this PS script (with my URL) as an example, I get the following error:

    Invoke-RestMethod : The ‘accept’ header must be modified using the appropriate property or method.
    Parameter name: name
    At line:30 char:1
    + Invoke-RestMethod @params
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    Any suggestions?

    1. Hi Joe,

      How does your accept header look like?

      Maybe you can share you script without the webhook so I can have a look?


      1. Joe says:

        Thanks for the quick reply – I used the $params assignment as in the powershell script above. When I remove the Headers assignment, the webhook worked great!

        However, I am still struggling with getting my on-prem TFS 2015 notifications to use the same webhook (on build failure, for example) – When I test the service hook from within TFS 2015, it yields a 400-Bad Request. Any ideas?

        1. Hi Joe,

          Maybe you can do some network tracing to find out how your web request message looks like? You could use Fiddler to see how your web request looks like.

          Hope this helps.


          1. Stephan says:

            Hi Stefan

            I’m trying to do pretty much the same with an on-premise instance of TFS, my example is just for a pull request but that should not matter

            Below is the message that it is trying to send as from the TFS test webhook popup when setting up a web hook:

            Method: POST
            HTTP Version: 1.1
            Content-Type: application/json; charset=utf-8
            “subscriptionId”: “00000000-0000-0000-0000-000000000000”,
            “notificationId”: 12,
            “id”: “2ab4e3d3-b7a6-425e-92b1-5a9982c1269e”,
            “eventType”: “git.pullrequest.created”,
            “publisherId”: “tfs”,
            “message”: {
            “text”: “Jamal Hartnett created a new pull request”,
            “html”: “Jamal Hartnett created a new pull request”,
            “markdown”: “Jamal Hartnett created a new pull request”
            “detailedMessage”: {
            “text”: “Jamal Hartnett created a new pull request\r\n\r\n- Merge status: Succeeded\r\n- Merge commit: eef717(\r\n”,
            “html”: “Jamal Hartnett created a new pull request\r\n\r\nMerge status: Succeeded\r\nMerge commit: eef717\r\n”,
            “markdown”: “Jamal Hartnett created a new pull request\r\n\r\n+ Merge status: Succeeded\r\n+ Merge commit: [eef717](\r\n”
            “resource”: {
            “repository”: {
            “id”: “4bc14d40-c903-45e2-872e-0462c7748079”,
            “name”: “Fabrikam”,
            “url”: “”,
            “project”: {
            “id”: “6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c”,
            “name”: “Fabrikam”,
            “url”: “”,
            “state”: “wellFormed”
            “defaultBranch”: “refs/heads/master”,
            “remoteUrl”: “”
            “pullRequestId”: 1,
            “status”: “active”,
            “createdBy”: {
            “id”: “54d125f7-69f7-4191-904f-c5b96b6261c8”,
            “displayName”: “Jamal Hartnett”,
            “uniqueName”: “”,
            “url”: “”,
            “imageUrl”: “”
            “creationDate”: “2014-06-17T16:55:46.589889Z”,
            “title”: “my first pull request”,
            “description”: ” – test2\r\n”,
            “sourceRefName”: “refs/heads/mytopic”,
            “targetRefName”: “refs/heads/master”,
            “mergeStatus”: “succeeded”,
            “mergeId”: “a10bb228-6ba6-4362-abd7-49ea21333dbd”,
            “lastMergeSourceCommit”: {
            “commitId”: “53d54ac915144006c2c9e90d2c7d3880920db49c”,
            “url”: “”
            “lastMergeTargetCommit”: {
            “commitId”: “a511f535b1ea495ee0c903badb68fbc83772c882”,
            “url”: “”
            “lastMergeCommit”: {
            “commitId”: “eef717f69257a6333f221566c1c987dc94cc0d72”,
            “url”: “”
            “reviewers”: [
            “reviewerUrl”: null,
            “vote”: 0,
            “id”: “2ea2d095-48f9-4cd6-9966-62f6f574096c”,
            “displayName”: “[Mobile]\\Mobile Team”,
            “uniqueName”: “vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team”,
            “url”: “”,
            “imageUrl”: “”,
            “isContainer”: true
            “commits”: [
            “commitId”: “53d54ac915144006c2c9e90d2c7d3880920db49c”,
            “url”: “”
            “url”: “”
            “createdDate”: “2016-11-22T06:27:44.3959863Z”

  2. Hugo Conceicao says:

    I can’t see WebHook messages in mobile (Android). (capture:

    1. Hi Hugo,

      You need to provide a bit more info on what you are doing if you want me to help you 🙂

      Microsoft Teams is working on my Android device.


      1. Hugo Conceicao says:

        Hi Stefan,

        I run your script(copy&paste) and works fine in Microsoft Teams desktop version, but on Android I can’t see the messages created from webhooks.

        I think the problem it’s related with text color, because if do “Copy message” the message is there.


        1. Hi Hugo,

          Maybe it’s something with the Android client for teams. Could try asking your question at UserVoice?

          Sorry for being able to help you further with this question.


  3. Don says:

    Works like a charm! However, the PowerShell messages don’t show in the Windows Phone 10 Teams app, only replies to these messages.

    1. Hi Don,

      Looks like this is a bug at the Windows Phone app. According to the Desktop Team app the messages show up.

      Maybe you can post your question at Uservoice?

      Sorry I cannot really help you with this question.


  4. Debra White says:

    Nice post, Thanks!

    If my understanding is correct, currently Connectors can only push content into Teams, not the other direction? For example, if I want to create an application to grab existing posts in the channel for further analysis, is that possible?

    1. Hi Debra,

      Yes you are right right now you can only push content using a webhook in Microsoft Teams. But if you want to start developing Apps for Microsoft Teams please check the following link:

      Hope this helps.


  5. Dheeraj says:

    Can we hook the postman test script to microsoft teams?

    1. Hi Dheeraj,

      What would you like to do with Postman Test script.


  6. John Schmalhorst says:

    How can I incorporate @mentions?

  7. Frank says:

    How we can delete the messages from connector? I didn’t see any “more options”

    1. Hi Frank,

      Check this response on UserVoice on deleting messages.

      Hope this helps.


      1. Frank says:

        Thanks Stefan, but it seems not to answer my question.

        1. Hi Frank,

          To my knowledge there is currently no way to delete messages via the connector that’s why I referenced UserVoice link.


  8. Gaz says:

    HI, is there a way to upload images please? I’ve yet to find any websites explain this with an example that works for powershell. Thanks

Comments are closed.

Skip to main content