This blog post is a continuation of the work we did in:
- Use Microsoft Lists and Power Automate to provision Microsoft Teams
- Use MS Lists and Power Automate to provision Private Channels in Teams
- Use Power Automate to get a MS Teams SharePoint URL
Drawing inspiration from a PMO (project management office) team managing multiple projects from a centralized List in mind, we will copy template files to the project team as part of the provisioning process.
Part 1 – Update “Projects” list
I’ve added a new Hyperlink column, called “SharePoint Link” to the “Projects” list.
|Column name||Column type|
|Title||Title used to store the project name.|
|Description||Single line of text used to store the project description.|
|Visibility||Choice with the following options: “Private” and “Public”. Indicates if a team should visible to non-team members.|
|Owners||Person or Group with Allow multiple selections enabled.|
|Members||Person or Group with Allow multiple selections enabled.|
|Link||URL used to store the web link to the newly created Teams team.|
|Private Channel Owner||Person. Important: do not allow multiple selections. We can only add one owner to the private channel using Graph.|
|SharePoint Link||Hyperlink used to store the SharePoint site associated with the newly created Teams team.|
Part 2 – Update Flow Get SharePoint URL
I’m updating the Flow created in Use MS Lists and Power Automate to provision Private Channels in Teams to include the steps required to get the underlying SharePoint site URL of the newly created Teams team. My starting point looks like the image below.
Add a Azure AD – Get group step and set Group Id to “Team ID” from the previous Get a team step (contained in the Condition action).
Insert a new HTTP action and set:
- Method to “GET”
- URI to https://graph.microsoft.com/v1.0/groups/<Id>/drive where <Id> is from the previous Azure AD – Get group step
- Authentication to “Active Directory OAuth”
- Tenant to “variables(‘varConnectInfo’)?[‘varDirectoryID’]”
- Audience to https://graph.microsoft.com
- Client ID to “variables(‘varConnectInfo’)?[‘varApplicationID’]”
- Credential Type to “Secret”
- Secret to “variables(‘varConnectInfo’)?[‘varSecret’]”
Save and test the Flow. Copy the output from the HTTP step.
Add a Parse JSON step, set:
- Content to “Body” from the previous HTTP step
- Click “Generate from sample” and past in the copied output from the previous HTTP step
Insert a new Initialize variable and set Name to “varWebURL”, Type to “String” and Value to following expression:
substring(body('Parse_JSON_-_Get_Group_Drive')?['webUrl'], 0, lastIndexOf(body('Parse_JSON_-_Get_Group_Drive')?['webUrl'], '/'))
This expression trims the Document Library path from the site URL.
Insert a new SharePoint Update item action and set:
- 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
- SharePoint Link to the “varWebURL” variable
At this point in the Flow we create a new Teams team, add a private channel, get the SharePoint URL and save it back to our List. In the next section we will check for the General folder in the Groups default drive. The General folder maps back to the General channel in the team. As I understand it, the default Files tab does not provision until you visit the team. To work around the delayed provisioning we will check for the folder and if it does not exist create it.
Part 3 – Update Flow Copy Files
Insert a new Scope action. This will be our “Try” for a Try-Catch-Finally pattern. Add a SharePoint Get folder metadata using path action and set:
- Site address to “varWebURL”
- Folder Path to “/Shared Documents/General”
Insert another Scope action. This will be our “Catch” for the Try-Catch-Finally pattern. Add a SharePoint Create new folder action and set:
- Site address to the “varWebURL” variable
- List or Library to “Documents”
- Folder Path to “/General”
Click the ellipse on the Scope action, select “Configure run after”. Set Scope – Try to “has failed” and click “Done”.
This means that Flow will create the General folder if check for the General folder fails.
Insert another Scope action. This will be our “Finally” for the Try-Catch-Finally pattern. Add a SharePoint Copy folder action and set:
- Current Site Address to your source site that is hosting the project files
- Folder to Copy to your source folder that is storing the project files
- Destination Site Address to “varWebURL”
- Destination Folder to “/Shared Documents/General”
- If another folder is already there to “Replace”.
My completed and albeit lengthy, Flow is shown in the image below.
Test by creating a new row in the Projects list.
If all goes well your Flow will execute without errors, a new Teams team (1) with a Private Channel (2) will be created and the project files (3) will copied to the team!
I find it amazing that with a List and Power Automate you can piece together a Teams provisioning solution without too much fuss. I wouldn’t use this solution for provisioning at large scale (think thousands) but I would for small-to-mid scale (think hundreds) use cases where consistency, control and eliminating manual efforts are the goal. I reference a PMO throughout these posts as a source of inspiration but this solution could easily be tailored for uses like committee management or mass departmental team creation.
Thanks for reading.