Utilizing Message and Adaptive Playing cards with Powershell in Electronic mail and Microsoft Groups in Workplace365

Utilizing Message and Adaptive Playing cards with Powershell in Electronic mail and Microsoft Groups in Workplace365 Playing cards are “a user-interface (UI) container for brief or associated items of knowledge ref” which there are at present two codecs for, MessageCards and AdativeCards . The underlying knowledge format is a JSON object that describes the content material to be rendered by a supporting consumer. Eg here’s a primary pattern

So they’re a easy means of presenting info in constant method which  then makes deploying that very same UI expertise throughout a number of consumer varieties components (cell,internet,desktop) quite a bit simpler.  Playing cards additionally help you outline actions, so then the playing cards themselves can change into a small app or a part of an integration piece of a Line of Enterprise workflow and many others. Actionable Playing cards in Outlook have the flexibility to hyperlink with an Outlook Addin’s see which begins to actually lengthen what you should use playing cards for. This implies your not simply caught within the restricted characteristic set of Playing cards however you should use the richness out there within the Outlook Addin framework.

Electronic mail Safety  

Playing cards rely on JSON (JavaScript Object Notation) and JavaScript to offer the performance that they do. Messaging folks which have been round for some time would know that JavaScript (and different energetic Content material) in Electronic mail our bodies hasn’t been allowed for a really very long time due to the chance of malicious code execution. Therefor senders of Actionable playing cards have to be registered with Microsoft and Authorised utilizing the next portal . In the event you simply wish to ship Actionable messages inside your personal tenant you’ll registered your App inside your tenant however your Actionable Messages wouldn’t have any context exterior of your tenant (or different peoples Actionable Messages inside your personal).

Shopper Help 

 If you’re a pupil of Know-how playing cards are examine into cloud cadences and simply how rapidly requirements can come and go now but additionally how arduous it may be to get all of your software program wheels turning to maintain tempo. For instance MessageCards are actually thought-about legacy nevertheless as of this put up June 2018 each the Outlook desktop  and the Staff’s purchasers do not help adaptive playing cards of their present common releases.  Eg for Adaptive Playing cards help in Groups you’ll need the developer preview and within the Outlook Desktop consumer it’s essential be on the Month-to-month Channel with model 1085. That is neither good nor unhealthy however for those who discover Adaptive Playing cards the precise factor it’s essential resolve your drawback you ought to be conscious of consumer help standing earlier than you begin your planning. 


For this put up I’ve created each a MessageCard PowerShell pattern that may use be utilized in both Outlook or Groups and a Adaptive Playing cards pattern that can be utilized main in OWA in the meanwhile. The to supply simply the MessageCard might be discovered https://github.com/gscales/Powershell-Scripts/blob/grasp/CreateMessageCard.ps1 and the Adaptive Card https://github.com/gscales/Powershell-Scripts/blob/grasp/CreateAdaptiveCard.ps1

Microsoft Groups – In/Out – Out of Workplace Groups Message card

This script will produce the next output to a Groups Channel utilizing a incoming WebHook to obtain the Messages

This instance makes use of my Exch-REST module out there from the PowerShell Galleryhttps://www.powershellgallery.com/packages/Exch-Relaxation and GitHub https://github.com/gscales/Exch-Relaxation . This accommodates all of the code to first get the Group related to a selected crew, get the members of that teams mail Addresses, make the Graph Mail suggestions request after which bundle the outcomes as JSON message which might then be posted to a WebHook.

To Setup a WebHook for the script to put up to on a Staff see https://docs.microsoft.com/en-us/microsoftteams/platform/ideas/connectors#setting-up-a-custom-incoming-webhook

 So lets take a look at how this all suits collectively

Join-EXRMailbox -mailbox [email protected]

$GroupName = "A Team"
$Group = Get-EXRModernGroups -GroupName $GroupName
$Members = Get-EXRGroupMembers -GroupId $Group.id

The above code first will get the ModernGroup which is related to the Staff you’re working with utilizing the Groups DisplayName. It then makes use of the GroupId that’s returned to make a request to Get the Members of that group.

$OOFMailboxCol = @()
$mtHash = @{}
foreach($Member in $Members){
        $OOFMailboxCol += $Member.mail

This code creates a set of Mailboxes to make use of the Get-EXRMailTips operation and likewise creates a hashtable to permit us to map the e-mail tackle within the Mailtips response again to the DisplayName as a result of by default MailTips solely provides you again the EmailAddress.

$Mailtips = Get-EXRMailTips -Mailboxes $OOFMailboxCol -tips "automaticReplies"

$FactsColl = ($Mailtips | choose @{Title='EmailAddress';Expression={$mtHash[$_.emailAddress.address]}},@{Title='OOF Message';Expression={$val =($_.automaticReplies.message -replace '<[^>]+>','').Trim();if([String]::IsNullOrEmpty($val)){"In"}else{"Out : " + $val}}})

$WebhookAddress = "https://outlook.office.com/webhook/cc1b7a"

Invoke-WebRequest -Uri $WebhookAddress -Technique Put up -ContentType 'Utility/Json' -Physique (New-EXRMessageCard -Info $FactsColl -Abstract "Team OOF Status" -Title "Team OOF Status")

The primary line of the above code makes the MailTips request for the addresses which can be handed into it. The following line builds a Assortment of Info which is a Messagecard aspect that show a two column desk. I’ve used expressions to wash up the outcomes because the MailTips response is a HTML worth that must be formatted again to textual content for the cardboard and I’ve added some In/Out prefixes based mostly on the response. The final line of code is what submits the Message card to the configured webhook tackle within the $WebhookAddress variable.

The Full Sourcecode for this script might be discovered https://github.com/gscales/Exch-Relaxation/blob/grasp/Samples/SendOOFMessageCard.ps1

Adaptive Card to point out the Workplace365 Service well being standing
As I discussed beforehand in case your going to ship an Adaptive Card as an e-mail it’s essential be registered within the portal and embody the originator Id you obtain in your adaptive Card. For testing what you are able to do is ship an Adaptive Card to your self (from your self) and with out the originator property being set and it’ll seem okay. However for those who the place to ship it to another person the content material will probably be stripped from the message.

One of many different issues which you could get from the handle.workplace.com endpoint that I talked about on this put up is the Service Well being details about every of the totally different workloads in Workplace365. On this instance I exploit the Administration API to supply the next adaptive card instance eg

Adaptive Playing cards have much more formatting choices for instance you possibly can have a column set and use totally different font colours. To make the script as dynamic as attainable I do the colour switching utilizing a hashtable. This instance makes use of my Exch-REST module out there from the PowerShell Galleryhttps://www.powershellgallery.com/packages/Exch-Relaxation and GitHub https://github.com/gscales/Exch-Relaxation  . The script does the next

$To = "[email protected]"
Join-EXRMailbox -MailboxName "[email protected]"
Join-EXRManagementAPI -UserName "[email protected]"
$StatusArray = Get-EXRMCurrentStatus | Choose-Object WorkLoad,Statusdisplayname,StatusTime 

Within the above code it makes a connection to the Mailbox and ManagementAPI after which builds an assortment for the service well being info.

$ColorSwitchHash = @{}
$ColorSwitchHash.Add("Service degradation","attention")
$ColorSwitchHash.Add("Normal service","good")

This code units up a HashTable that will probably be used to show a distinct shade for the service standing column based mostly on its standing. Observe the Adaptive Playing cards help a subset of the MarkDown format so consideration (crimson), good (inexperienced) and many others.

$Card = New-EXRAdaptiveCard -Columns $StatusArray -ColorSwitchColumnNumber 1 -ColorSwitchHashTable $ColorSwitchHash -ColorSwitchDefault warning
Ship-EXRAdaptiveCard -To $To -Topic "Office 365 Service Status" -AdaptiveCard $Card

The final a part of the code generates the AdatpiveCard, the ColorSwitchColumnNumber is a zero based mostly array to match with the gathering that’s handed in. What Ship-EXRAdaptiveCard does is wraps the JSON from the Card within the following script which is important whenever you ship a message.

<script sort="application/adaptivecard+json"></script>

Rent me – I am at present out there to assist with any ExchangeOffice365 associated growth work or scripting please contact me at [email protected] (nothing too large or small). I would even be curious about listening to from any corporations that wish to sponsor open supply initiatives round Alternate and Workplace365 growth.


Related Posts

Leave a Reply