Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 26

Recently I was asked about creating a team template in Microsoft Teams and apply this team template to a team created using Power Automate.

Education tenant

As I mentioned a while ago the Education Microsoft Teams tenants are very different compared to the business tenants.

For this post I’m going to create a template team as a class team. Then i will use this template to create a new team. The template will include some channels and some documents a in the channels. All the documents will need to be copied and the channels will need to be created.

Creating a Teams team template

First steps first, I will go to Microsoft Teams and create a new class team.

In Teams I’m going to the overview of all my Teams and then I click on the Join or create team.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image

Now I can create my template Team

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 1

This is where I select the Class team type for my template site.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 2

Then i supply the details of my template site.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 3

You will notice that there is a link Create a team using an existing team as a template this is an alternative to the method described in this post if you can create teams manually. But if you want to do things in an automated way you will have to find some alternatives.

Anyway, we now have a team that is being created.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 4

We are now ready to add some channels. I’m going to add a standard channel for Students and a private channel for teachers.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 5

And Once I’ve created both channels, I just need to add some documents to each channel and then I’m done.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 6

Note that the private channel might take a bit longer to be created, but after awhile the Files tab will show you an empty document library.

Now we have our template completed.

Copy a Microsoft Teams template site

So far all was easy, but now we’re going to look at the Power Automate part of the solution.

So I first go to my Power Automate site and I create a flow. I will initially use a manually starting flow but later on I would for example trigger the flow on the upload of a csv file that supplies me with the details of the teams that needs to be created.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 7

And now you might hope that you could simply create a new team using the Create a team action. But that isn’t going to work.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 8

When we use this action we will only find very few option. The education part is missing. I wonder if the Power Automate team forgot that there are educational tenants. So when we want to use the team template we might have to do a bit more work.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 9

I’m going to use the Graph API. To do the Graph API I will go through the steps similar to some of my previous posts. like for example last week’s post Who is in the office tomorrow.

Creating the app registration in Azure Portal

In the app registration blade I will complete the following details:

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 10

As always I then create a secret:

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 11

And then I need to set the API Permissions:

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 12

The API permissions that I need are:

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 17

This means that in the app registration you want to add the application permissions Group.ReadWrite.All and Directory.ReradWrite.All.

Isn’t that nice. We don’t need any teams permissions to clone a team.

Building the flow to copy the team template

Then I create a Select action in the flow that has 3 mappings configured. and the SecretId, ClientId and the Tenant ID are copied from my app registration in Azure.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 14

Then I rename the above select action to Settings and add a Parse JSON action to following the above action

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 15

The content expression in the above Parse JSON settings is set to:

first(body('Settings'))

Now to get an access token for the Graph API we need to add an HTTP action that will collect the access token. using the Tenant ID and the ClientID and the SecretId as configured earlier.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 16

Then the access token can be collected from the above HTTP action using the following expression

body('HTTP')?['access_token']

Now that we have an access token it is time to have a look at how we can clone the template team.

Cloning a team using Power Automate

Now following the HTTP request that gets the access token I will add a get a team action. This is where i select my template team

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 19

then in another HTTP request I’m adding all the details for the team calling the following endpoint

https://graph.microsoft.com/beta/teams/@{outputs('Get_a_team')?['body/id']}/clone
Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 18

So, the flow worked. Time to checkout my new team!

In my teams overview it looks good!

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 20

Then inside my team:

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 21

Ok, so the Student Information channel has been created. That is my public channel. The private channel is not being created.

A bit disappointing maybe as a clone should be a clone and not a poor copy, but hey, we can sort that out!

Creating a private channel

To created a private channel you have to specify an owner. So i’m first going to collect the user id for a suitable owner.

Using the Search for a user I will find a user.

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 23

And then in the following compose I collect just the first person returned by the query as I know that I will only have one person being returned this is something that will be safe.

The expression used is:

first(outputs('Search_for_users_(V2)')?['body/value'])

To Create a new channel we will need yet another Graph API call. The Create a Channel endpoint will require us to update the app registration permissions to include the following application permission:

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 22

Then we configure the HTTP request to create the private channel and success!

Create a Microsoft Teams team template Microsoft Office 365, Microsoft Power Automate, Microsoft Teams image 24

The private channel has been created matching my original team template, including the private channels

The private channel has been created matching my original team template
Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as a Principal Architect at HybrIT Services Ltd. You can contact me using contact@sharepains.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d bloggers like this: