After playing around with the Teams cmdlets in Azure Automation I tried to use them in Azure Functions. Should be pretty forward given the fact you can upload your own modules to your function in a matter of minutes.

Well, it took me some hours. But let’s get started.

To upload a custom PowerShell module have a look at https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/ This gives a good overview of all the steps needed to run your scripts in your function.

To get the files of the Teams module use this PowerShell command:

The directory should look like this now:

You can use ftp now to upload the whole “MicrosoftTeams” folder to a subfolder called “Modules” in your Azure Function. The expected folder structure should be like this:

Now you can start to use the Teams cmdlets in your Azure Function, or at least you should be able to do so. But instead I get an error like this:

All we try at this moment in the function looks like this:

Same few lines run fine on my local machine and in the Azure Automation Runbook, but not in the Azure Function. After sniffing around I came across the references made in MicrosoftTeams.psm1. In the default way this file looks like this:

In line 14 there is a reference to the DLL my Azure Function is complaining about. Turns out if you just modify this file and get rid of this reference the function is up and running.

I now can create a new Teams team with the cmdlets running in an Azure Function. 

And here is the team:

This leaves me with two options. The first one would be that I’m missing something in the usage of the Teams PowerShell cmdlets in Azure Function. Could be of course, but as there is a reference to a local file in the module definition and this file isn’t installed on my machine, my guess is that there will be an update to this cmdlets very soon. Also, some other guys are playing with the cmdlets already and let’s say it in a diplomatic way, their feedback leaves some room for improvement. 

Just to be totally clear, this “hack” here is in no way meant to be used in a production environment. It’s just a way to get this up and running but please don’t use it in production, or at least don’t complain after something breaks.