Using Connectors to deliver messages to Teams and Outlook
We’ve modified the script we shared in our previous post, to call a Teams and/or Outlook Webhook Connector from PowerShell.
There is a quick one-time process to add an Incoming Webhook connector to your Teams channel and Outlook Group or account. Doing so will get you a webhook URI that you’ll hardcode into the script linked above.
In the Office 365 Mail app, go to Settings in the upper right-hand corner. For Groups, click on the Group and go to Group Settings in the upper right-hand corner.
Click Manage Connectors > Incoming Webhook > Add.
Give the connector a name and image (optional) of your choosing and finally click Create.
A new unique URI is automatically generated. Copy this URI string to your clipboard.
Now that you have a way of pulling these messages out of the Office 365 admin portal, the next step is to make things easier by automating this process. You probably have your own preferences and tools for doing this. Here, we’re sharing how you can use Azure functions to run the script on a timer. Another way to do this is in this blog post: Using Azure runbooks to get Intune messages delivered on a schedule
Creating an Azure function to run the script on a timer
Enter a name for your function. The rest of the fields will autofill. Click Create.
Click on notification icon in the upper right-hand corner to see if your deployment was successful. Click ‘Pin to Dashboard’ to make it easier to find your function.
Expand your function that is now open and click on the + button next to Functions. Click on ‘create your own custom function’.
Change toggle for experimental language support to Enabled.
Search for the function Timer Trigger and open the template.
Choose language with the default timer schedule which is a six field CRON expression. Click create.
Expand the function and click Integrate to make any further changes to the timer schedule after you’ve created the function or any time in the future. Expand Documentation to see examples of different schedule expressions.
Now comes the time to make changes to your settings. Click on your function which is named TimerTriggerPowerShell1 in this screenshot.
Modifications to Function App Settings: - If you are planning to run the GetMessagesTeamsOutlook script via the TimerTrigger Azure function, modify the script to use the EnsureADModuleInAzureFunction instead of EnsureAzureADModule.
- Configure FTP/Deployment credentials in Azure by going to your Function App >> Platform features >> Deployment credentials, using the steps detailed here under the section titled "Where can I store ...". This username and password will be the same across all apps in all subscriptions associated with your Microsoft Azure account. - Use the FTP Hostname or FTPS Hostname and with an FTP client of your choice to upload the DLLs shown in the next step. - To use EnsureADModuleInAzureFunction, the two DLLs in the script shown in the screenshot below need to be uploaded to the Azure function app. Note: These files will be on your machine if you have run the GetMessages script once locally. Depending on your Azure function app name and upload folder, you will need to modify the path specified in this portion of the script: “TimerTriggerPowerShell1\AzureAd”
Here’s where you’ll paste in your GetMessagesToTeamsAndOutlook PowerShell script with your credentials and URIs filled in. Before using the Azure function for automation, the script needs one more modification. Be sure to uncomment and call EnsureAzureADModuleInAzureFunction instead of EnsureAzureADModule in the script.
Click Save. Message Center posts will now automatically be delivered to either Teams or Outlook or both, depending on what you’ve chosen, on the schedule that you have configured in your TimerTrigger function.
We hope this gives you more flexibility with where you receive your message center posts! Let us know if you have any questions or suggestions.