How to Create Teams’ Adaptive Cards with Webhooks Using PowerShell


The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

This blog post will show you how to use a webhook in the PowerShell tool set to create adaptive cards for each team on your site. We’ll be using C#, but it’s easy enough code that any language can translate this into their preferred syntax and function.

The “teams incoming webhook attachment” is a method that allows users to create teams’ adaptive cards with Webhooks. This method can be done using PowerShell.

How to Create Teams' Adaptive Cards with Webhooks Using PowerShell

Have you ever wished to personalize the appearance of your Teams by designing your own cards in channels with ease? Teams enables you to build and alter multiple cards in Teams using JSON using a concept called Adaptive Cards. You could make these by inputting some JSON, but using incoming Teams webhooks and a little PowerShell is a lot more fun!

You’ll learn not only how to make adaptive cards using PowerShell, but also how to construct legacy cards using webhooks and PowerShell in this lesson!


Only a few requirements are required to read this content.

Using Microsoft Teams to set up a Webhook Connector

Configuring Microsoft Teams to receive incoming messages through a Teams webhook or a connector is the first step in getting started with any webhook.

If your team’s Settings —> Member permissions —> Allow members to create, update, and remove connectors is selected, any team member can add, modify, or delete a connector.

To create an incoming webhook connection, follow these steps:

  1. Navigate to the Team for which you wish to setup the Teams webhook in Teams.
  2. As seen in the image below, right-click on the channel you want to send the notification cards to and choose Connectors.

Microsoft Teams now has a connection.Microsoft Teams now has a connection.

3. Click Add next to the Incoming Webhook option.

4. Click Add again in the pop-up window to attach the Incoming Webhook to the channel.

In the Teams Channel, add the Incoming Webhook.In the Teams Channel, add the Incoming Webhook.

5. Give your webhook a name. This name should accurately describe the integration you’re intending. If you’d like, you may also submit an optional picture. This image will appear as the incoming card’s “profile” photo.

For Teams, create a new webhook connection.For Teams, create a new webhook connection.

6. When you’ve finished configuring the webook, click Create.

7. After you click the Create button, a unique URL will be produced for you to use when you POST material to Teams. By using the copy button, you may save this URL. This URL will be required later in a PowerShell script. If you don’t copy it right now, you’ll be able to recover it later from the same setup panel.

Complete the connection by retrieving the webhook URL.Complete the connection by retrieving the webhook URL.

This is an example of a URL like this, and it’s the one we’ll use in the lesson.[email protected] 5d4bbf18f/IncomingWebhook/6d90a61335754f7dbaf2e8ddba924a33/64a9850c-7a4d-4f2a-826b-0ff3910c408c

As many connections (Teams webhooks) as you need are possible. Below is an illustration of two distinct channel connections. The Connections window may then be used to manage these connectors. You may need numerous connections to distinguish between various integrations.

Configure the new connector and any existing one's connected to the Teams channel.Set up the new connection, as well as any others that are linked to the Teams channel.

The channel will display a notice indicating the webhook has been added after you’ve setup it, as seen below.

The webhook was added to the channel, and the teams were notified.The webhook was added to the channel, and the teams were notified.

You can now construct some PowerShell to send messages to that webhook and generate some Adaptive cards now that you’ve established a connector (webhook) to take messages!

Creating Legacy Cards using PowerShell

You should be acquainted with the legacy card format before learning about adaptive cards. Why? Because the process of creating legacy cards using PowerShell is similar to that of creating Adaptive cards, but certain choices aren’t accessible in Adaptive cards. This older style is more straightforward and enables you to include various parts, photos, and information (a name-value list).

Here’s an example of how to make a legacy card. You’ll see that you’re utilizing the URI you got from the connection you made before. The comments provide any pertinent information about the code.

$URI = ‘<[email protected] 5d4bbf18f/IncomingWebhook/6d90a61335754f7dbaf2e8ddba924a33/64a9850c-7a4d-4f2a-826b-0ff3910c408c>’ # @type – Must be set to `MessageCard`. # @context – Must be set to [``](<>). # title – The title of the card, usually used to announce the card. # text – The card’s purpose and what it may be describing. # activityTitle – The title of the section, such as “Test Section”, displayed in bold. # activitySubtitle – A descriptive subtitle underneath the title. # activityText – A longer description that is usually used to describe more relevant data. $JSON = @{ “@type” = “MessageCard” “@context” = “<>” “title” = ‘Test Card Title’ “text” = ‘Typically used to describe the purpose of the card.’ “sections” = @( @{ “activityTitle” = ‘Test Section’ “activitySubtitle” = ‘Section Subtitle’ “activityText” = ‘Descriptive text for the activity.’ } ) } | ConvertTo-JSON # You will always be sending content in via POST and using the ContentType of ‘application/json’ # The URI will be the URL that you previously retrieved when creating the webhook $Params = @{ “URI” = $URI “Method” = ‘POST’ “Body” = $JSON “ContentType” = ‘application/json’ } Invoke-RestMethod @Params

When you execute the following code, a card message will show in the Teams client as a consequence (web, desktop, or mobile). This message will be formatted as in the example below, using the code provided above.

Demonstrate how to send a message using the standard way.Demonstrate how to send a message using the standard way.

You may have many parts with data, such as facts and definition list items. There are other things like heroImage, actions, and groups. Following that, we’ll discuss how adaptable cards may help you take your message to the next level.

Using Adaptive Cards to Improve Messages

Let’s look into Adaptive Cards and how they can improve the presentation of cards in Microsoft Teams now that you’ve seen how legacy cards operate. One interpretation of the same card as in the previous case is shown below. The syntax is significantly more verbose than in the original legacy example, as you can see.

It’s possible you’ve noticed that the [Ordered] type is used on occasion; this builds an ordered dictionary. It keeps the attribute order while debugging, when a typical hashtable would not. This is not required, but it is useful.

$URI = ‘<[email protected] 5d4bbf18f/IncomingWebhook/6d90a61335754f7dbaf2e8ddba924a33/64a9850c-7a4d-4f2a-826b-0ff3910c408c>’ # type – Must be set to `message`. # attachments – This is the container for the adaptive card itself. # contentType – Must be of the type `application/`. # content – The header and content of the adaptive card. # $schema – Must have a value of [``](<>) to import the proper schema for validation. # type – Set to the type of `AdaptiveCard`. # version – Currently set to version `1.0`. # body – The content of the card itself to display. $JSON = [Ordered]@{ “type” = “message” “attachments” = @( @{ “contentType” = ‘application/’ “content” = [Ordered]@{ ‘$schema’ = “<>” “type” = “AdaptiveCard” “version” = “1.0” “body” = @( [Ordered]@{ “type” = “Container” “items” = @( ## The different contained elements such as TextBlock or an Image. @{ “type” = “TextBlock” “text” = “Test Card Title” “wrap” = $true ## whether to wrap text that expands past the size of the card itself. “weight” = “Bolder” ## Whether to show the card as bolder, lighter, or as the default. If omitted then the text will be shown as default. “size” = “Large” ## The size of the text ranging from small, default, medium, large, or extralarge. If omitted then the text will be shown as default. } @{ “type” = “TextBlock” “text” = “Typically used to describe the purpose of the card.” “wrap” = $true } ) } [Ordered]@{ “type” = “Container” “style” = “emphasis” ## Two different styles available are emphasis and default. “items” = @( @{ “type” = “TextBlock” “text” = “Test Section” “weight” = “Bolder” “wrap” = $true } @{ “type” = “TextBlock” “text” = “Section Subtitle” “size” = “Small” “wrap” = $true } @{ “type” = “TextBlock” “text” = “Descriptive text for the activity.” “wrap” = $true } ) } ) } } ) } | ConvertTo-JSON -Depth 20 $Params = @{ “URI” = $URI “Method” = ‘POST’ “Body” = $JSON “ContentType” = ‘application/json’ } Invoke-RestMethod @Params

After you’ve generated the adaptable card by using the code above to contact the Teams webhook, enter Teams to view the different parts you’ve made.

The components of an adaptable cardThe components of an adaptable card

Increasing the Size of Our Display

You saw an example of a basic Adaptive card in the previous section. Now we’ll show you how to make a card with two columns and a list of facts or definitions. ColumnSet and FactSet are used in this example to build the columns and the list of facts to show. The code and comments show just a portion of the various choices, but they are sufficient to explain how this works.

# Columns Options: # width – This may be “auto” or “stretch” in type. Stretch implies it will fill the available container width, while auto means it will just extend to the content. # FactSet Options: # title – Boldly show the fact’s title. # value – The fact’s related value. [Ordered] @ “type” = “Container” “items” = @(@ “type” = “TextBlock” “text” = “Test Card Title” “wrap” = $true “weight” = “Bolder” “size” = “Large” @ “type” = “TextBlock” “text” = “Test Card Title” “wrap” = $true “weight” = “Bolder” “size” = “Large” “text” = “Typically used to describe the purpose of the card.” “wrap” = $true ) @ “type” = “TextBlock” “text” = “Typically used to describe the purpose of the card.” [Ordered] “type” = “ColumnSet” @ “type” = “ColumnSet” @ “type” = “ColumnSet ## We receive the ability to split material into columns as well as a range of display styling options with ColumnSet. “items” = @(@ “type” = “FactSet” “width” = “stretch” “columns” = @(@ “type” = “Column” “width” = “stretch” ## The Facts list in the original legacy card type is comparable to FactSet. “title” = “Fact 1” “value” = “Value 1” “facts” = @(@ “title” = “Fact 1” “value” = “Value 1” @ “type” = “Column” “width” = “stretch” “items” = @(@ “type” = “FactSet” “facts” = @(@ “title” = “Fact 1” “value” = “Value 1” @ “title” = “Fact 2” “value” = “Value 2” @ “title” = “Fact 3” “value” = “Value 3” @ “title” = “F

Columns and statistics have been added to the card design.Columns and statistics have been added to the card design.

That concludes our discussion. With PowerShell, you’ve now produced both a legacy and an adaptive card!

Steps to Follow

As you can see, adopting adaptable cards has a lot of benefits over the old card format. You’ll be able to present cards that are considerably more useful to Microsoft Teams members thanks to a variety of display settings, actions, and formatting. You can rapidly implement this way into your scripts using the easy method of producing adaptable cards using a webhook and Invoke-RestMethod in PowerShell!

If you want to learn more, go through the Microsoft website to see all of the choices you have for generating adaptable cards.

“Adaptive cards microsoft teams” is a feature that Microsoft Teams has recently added. The feature allows users to create adaptive cards with webhooks using PowerShell. Reference: adaptive cards microsoft teams.

Related Tags

  • teams webhook formatting
  • microsoft teams incoming webhook example
  • unable to add incoming webhook in teams
  • how to create an adaptive card
  • teams message card format

Table of Content