Microsoft Teams Connector for Part 3

In my previous post I created PowerShell scripts to get event data and post messages to Microsoft Teams channels. View Microsoft Teams Connector for Part 2 for sample code how to do this.

In this post I will create an Azure Function App (Microsoft’s alternative to Amazon AWS Lambda functions) to run the scripts on a schedule, say 10 am each day . This could also be achieved with a simple scheduled task or cron job on a local virtual machine or a PowerShell runbook in an Azure Automation Account, however I don’t want to maintain a virtual machine with patches and OS updates, and Azure Function Apps could allow me to later develop this into a full app or bot that can interact with conversations in Microsoft Teams.

Azure Function App to run PowerShell on schedule trigger

I created a new Azure Function App service with default settings.

Before creating the triggers I used the ‘Function app settings’ (using link bottom left of the quickstart screen) to configure app setting environment variables and set the time zone of the app to my local time zone. This isn’t strictly necessary however it’s easier for me to create schedules in local time without having to convert to and from UTC time in my head.


In the Application Settings blade, add a new key value pair for WEBSITE_TIME_ZONE. Even though this Function App will not have any website, it runs on top of Azure App Services and functions use the same environment variables.


The values for WEBSITE_TIME_ZONE are listed in the Windows Embedded for Point of Service documentation. I entered AUS Eastern Standard Time because that’s where I live!

Creating a PowerShell Azure Function

Selecting ‘Create your own custom function’ at the bottom of the Quickstart screen displays a grid of templates. The Language filter can show the templates where Language = PowerShell.


Select the TimerTrigger-PowerShell and name the function. Enter the schedule (using the local time zone you set above) in cron format:
[seconds] [minutes] [hours] [days of months] [months] [day of week]
Note the first value represents seconds (most Linux cron jobs only have hours and minutes).

AzureFunctionName.PNGThe above schedule will trigger the function at 12:05pm (midday)  every Monday (day of week = 1).

Create the function and a run.ps1 panel will be displayed in the Develop blade.

Copy / paste the entire PowerShell script you want to run into this panel and save.


That’s it! The PowerShell script will be executed on the specified schedule.

Using the code examples from Part 2 I created a Post-MeetupSummary function that runs every Monday at 12:05 pm, and a Post-MeetupDetail Azure function that runs daily at 10:00 am. My Microsoft Teams channels now get automated reminders about upcoming events and our local tech community is growing every month!

I’ve been really impressed with how simple it was to get started with Azure functions and start running PowerShell scripts in a ‘serverless’ Functions as a Service. Looking forward to experimenting a lot more with Azure functions and the Azure Bot Framework!