Use MS Lists and Power Automate to provision Private Channels in Teams

In my previous blog post I showed how easy it is to Use Microsoft Lists and Power Automate to provision Microsoft Teams. In this blog post I will show how to extend the previous solution to include the creation of a Microsoft Teams Private Channel. At the time of writing there is no create Private channel action in Power Automate. This means we have to leverage the Graph API. I found creating the Graph API Connector complicated but it’s worth doing for all of the options that Graph brings to Power Automate.

There are three parts to this solution that range from easy to complex, at least in my experience:

  1. Create Graph API connection (complex)
  2. Update “Projects” list (easy)
  3. Create new Power Automate Flow (moderate)

Part 1 – Create Graph API Connector

From the Microsoft 365 admin center, open “Azure Active Directory”.

Azure Active Directory

Create a new app registration by selecting “Azure Active Directory”, “App registrations” and then “New registration”.

New app registration navigation

Enter an application “Name” i.e. Graph API; set “Supported account types” to “Single tenant”, leave the “Redirect URI” blank and click “Register”.

Important: Save the “Application (client) ID” and the “Directory (tenant) ID” for later use in Power Automate.

Application (client) ID and  Directory (tenant) ID.

Click “API permissions”, click “Add a permission” and then click “Microsoft Graph”.

Add API permissions

Select “Application permissions”.

Request API permissions

Search for and apply the following permissions:

PermissionAdmin consent required
Group.Read.AllYes
Group.ReadWrite.AllYes
GroupMember.ReadWrite.AllYes
User.ReadNo
User.Read.AllYes
User.ReadWrite.AllYes
Request API permissions

Click “Grant admin consent” and then “Yes” when prompted.

Grant admin consent

Click “Certificates & secrets” and then click “New client secret”.

Certificates and secrets

Provide a “Description” i.e. Graph API, select an expiration date and then click “Add”.

Add client secret

Important: Save the client secret “Value” for later use in Power Automate. You will not be able to retrieve this value later!

Client secret info

Part 2 – Update “Projects” list

I’ve added a new Person column, called “Private Channel Owner” to the “Projects” list.

private channel owner
Column nameColumn type
TitleTitle used to store the project name.
DescriptionSingle line of text used to store the project description.
VisibilityChoice with the following options: “Private” and “Public”. Indicates if a team should visible to non-team members.
OwnersPerson or Group with Allow multiple selections enabled.
MembersPerson or Group with Allow multiple selections enabled.
LinkURL used to store the web link to the newly created Teams team.
Private Channel OwnerPerson. Important: do not allow multiple selections. We can only add one owner to the private channel using Graph.

Part 3 – Create new Power Automate Flow

Create a new Flow from the Projects list > Automate > Power Automate > See your Flows > Create new > Automated from blank. Provide a Flow name, i.e. “Teams provisioning with private channel”, select the SharePoint “When an item is created” trigger and click “Create”.

Create new automated Floe

Set the “Site Address” and “List Name” to your target site and list.

Create a new “Initialize variable” action. Set “Name” to “varConnectInfo”, “Type” to “Object” and “Value” to:

{
"varDirectoryID": "<Enter your Directory ID>",
"varApplicationID": "<Enter your Application ID>",
"varSecret": "<Enter your Client Secret Value>"
}

Create a new “Compose” action. Set “Inputs” to variable “varConnectInfo”.

Insert a new Microsoft Teams “Create a team” step. Set:

  • “Team Name” to “Title”
  • “Description” to “Description”
  • “Visibility” to “Visibility Value”
Create a team

Add a new “Condition” step to confirm the successful creation of the Teams team. Set:

  • “Choose a value” to “New Team Id” from the “Create a team” step
  • Condition to “is not equal to”
  • “Choose a value” to expression “NULL”
Condition check to ensure team was created

In the “If yes” branch insert a new Microsoft Teams “Get a team” step. Set “Team” to “New Team ID” from the Create a team action.

If yes

Insert a new Microsoft Teams “Add a member to a team” step – this is for Owners. Set:

  • “Team” to “Team ID” from the Get a team step
  • “A user AAD ID for the user to add to a team” to “Owners Email”
  • “Should the newly added user be an owner of the” to “Yes”
Add owners

Power Automate will place the “Add a member to a team” step into a “Apply to each” loop because the “Owners” column can store multiple selections.

Insert another new Microsoft Teams “Add a member to a team” step – this is for Members. Set:

  • “Team” to “Team ID” from the Get a team step
  • “A AAD ID for the user to add to a team” to “Members Email”
  • “Should the newly added user be an owner of the” to “No”
Add members

Insert a new SharePoint “Update item” step.

  • “Site Address” and “List Name” to your target site and list
  • “Id” to “ID” from the “When an item is created” step
  • “Title” to “Title” from the “When an item is created” step
  • “Visibility Value” to “Visibility Value” from the “When an item is created” step
  • “Link” to “Web Url of team” from the “Get a team” step

Add a new Office 365 Users “Get user profile (V2)” action. Set “User (UPN)” to “Private Channel Owner Email” from the create item step. The output from this step is used during the Graph API call.

Get user profile.

Now for the cool stuff! Add a new “HTTP” action to create the private channel. Set:

{
   "membershipType": "private",
   "displayName": "Private",
   "description": "This channel is private",
   "members": [
     {
       "@odata.type": "#microsoft.graph.aadUserConversationMember",
       "user@odata.bind": "https://graph.microsoft.com/beta/users('<Id>')",
       "roles": [
         "owner"
       ]
     }
   ]
 }

Where <Id> comes from the "Get user profile (V2)" action
  • “Authentication” to “Active Directory OAuth”.
  • “Tenant” to expression: variables(‘varConnectInfo’)?[‘varDirectoryID’]
  • “Audience” to “https://graph.microsoft.com&#8221;
  • “Client ID” to variables(‘varConnectInfo’)?[‘varApplicationID’]
  • “Credential Type” to “Secret”
  • “Secret” to variables(‘varConnectInfo’)?[‘varSecret’]

My completed Flow looks like the image below.

Completed Flow.

And my completed “If yes” branch looks like the image below.

If yes branch

Test by creating a new row in the Projects list.

new row

If all goes well your Flow will execute without errors and a new Teams team with a Private Channel will be created!

I know this is a long post for something that can be done manually but at scale for centralized deployment and management this is a great way to provision Teams for projects, committees and other types of working groups where control and consistency is key. Additional value comes in the form of gaining access to the Graph API for further actions in Power Automate.

Thanks for reading.

NY

3 thoughts on “Use MS Lists and Power Automate to provision Private Channels in Teams

Leave a Reply to elbruno Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s