The private channel has been created matching my original team templateThe private channel has been created matching my original team template

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 team in Teams
Create a team in Teams

Now I can create my template Team

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

Select a team type
Select a team type

Then i supply the details of my template site.

Create your team
Create your team

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.

Class team
Class team

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 channel in team
Create channel in team

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

Channels in my team
Channels in my team

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.

Copy a Microsoft Teams template site
Copy a Microsoft Teams template site

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.

Microsoft Teams actions in Power Automate
Microsoft Teams actions in Power Automate

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 team action
Create a team action

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 Team Management app registration in Azure
Create a Team Management app registration in Azure

As always I then create a secret:

Add a secret to the app registration
Add a secret to the app registration

And then I need to set the API Permissions:

Set the API permissions on the app registration
Set the API permissions on the app registration

The API permissions that I need are:

Required permissions
Required permissions

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.

A scope with my connection details
A scope with my connection details

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

Parse JSON to make it easier to select the properties
Parse JSON to make it easier to select the properties

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.

Get an access token
Get an access token

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

Cloning a team using Power Automate
Cloning a team using Power Automate

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
Clone a team
Clone a team

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

In my teams overview it looks good!

Teams overview
Teams overview

Then inside my team:

Team with Student Information channel
Team with Student Information channel

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 private channel
Create a private channel

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:

Permissions needed for API call
Permissions needed for API call

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

Private channel creation in Power Automate
Private channel creation in Power Automate

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
The private channel has been created matching my original team template
Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. 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