Wednesday, October 28, 2020

Microsoft Teams PowerShell Bot Example

Microsoft Teams has a lot of cool features. This article will show you how to write a simple PowerShell bot that will post messages to a Teams channel.

Configure the WebHook in MS Teams

  1. Open the MS Teams Channel you want to add the bot to
  2. Click Connectors


  3. Click the Configure button by the Incoming WebHook option


  4. Give your WebHook a name...such and such Bot and you can upload an image if you want. Scroll down and click Create
  5. On the create screen you will see a URL. Copy this URL and save it somewhere you will need it in your PowerShell Script.


PowerShell Script


Sample PowerShell Script Below.


The script will run a simple SELECT statement on a DB and will Send a WebRequest to the URL you setup in Teams. The Bot will post a message to the channel you configured for the Incoming WebHook above.













If you do not want to mess with the Card Format then you can just post a simple message like this.

You can update the SQL Statement to pull data and display it in whatever channel. 

0 comments:

Post a Comment