Create a new Team with Forms and Flow

With the introduction of MS Teams within your company, you as an admin are faced with the decision whether you want to keep creating new teams open for everyone or not. By default, it is possible for anyone with a license to create a new team within MS Teams. If you do not want this and want to control the creation of MS Teams a bit more, it’s an option to create a Form with a Flow that handles the creation of a team with Microsoft Graph.

Step 1 – Manage who can create Office 365 Groups

First of all, you configure who can create new Office 365 groups. This also removes the option in MS Teams to create a new team. Microsoft has created this step-by-step plan for this.

Step 2 – Create an App registration in AzureAD

We are going to create the team with the create team function in the Microsoft Graph REST API. To be able to address this from Flow with application rights, we create an app registration with Group.ReadWrite.All rights.

Create a new app registration

In the Azure portal, go to Azure Active Directory and select App registrations. Click on the New application registration button and enter the details. A valid website must be entered in the Sign-on URL, but since we are going to address the app from Flow, this is not relevant. After creating, note the Application ID that has been created.

To grant the required rights to this app registration, click on the Settings button. Then click on Required permissions and then on Add. At item 1 Select an API you select Microsoft Graph. Under section 2 Select permissions, select Read and write all groups under the Application permissions heading. Then an admin must approve the rights by clicking on Grant permissions and confirming.

Next we will create a key by going to the menu option Keys. Under Passwords, enter a self-designed description in the Description field, select Never expires and click the Save button. Copy the key that is now displayed and save it properly. This is the only time this code is displayed.

Key for access to the app registration

Finally, we still need the tenant ID. You can find this by going into the Azure portal to Azure Active Directory. There you click on Properties and then you copy the Directory ID code. This is your tenant ID.

Now you have:

  1. a tenant ID
  2. an application ID
  3. a password (a.k.a. Secret)

Step 3 – Create Form

Request new team form

Go to http://forms.office.com and create a new form. As an example I have created a form with 3 questions:

  • Name? – Text
  • Description? – Text
  • Kind of team? – Choice

Depending on the last answer, I let the team name start with Dep- or Proj-. I do this to show that you can set up something of a naming convention for your teams. For example, you could also set the department name at the start of every teamname.

Step 4 – Create the Flow

Go to http://flow.microsoft.com and create a new blank flow. Use the When a new response is submitted from Microsoft Forms as a trigger and select the form that you just created in step 3. Then initialize 4 new string variables and enter the data from step 2 in the first 3 variables. The last variable iniStrTeamStart must remain empty.

Initialize 4 string variables

Then create a new Get response details action and select the form that was created in step 3 again. InResponse Id, select the List of response notifications Response Id of the trigger. An Apply to each will now be created automatically.

Load data from Forms

Then create a Switch that looks at the value Kind of team?. Add the Department and Project options. Within those options we create a Set variable that changes the value StrTeamStart to Dep– or Proj-.

Switch on kind of team

We then have to retrieve 1 more variable and that is the ID of the applicant. When creating the team, we must specify who should become the owner. I want to use the applicant for this, so we first request the user profile with the Get user profile (V2) action. Because I only need the ID of the applicant, not his name or anything, I fill the Select fields with ID.

Get user profile (V2) action to retrieve ID of the requester

And then we have arrived at the actual creation of the team. We use the HTTP action for this and will use it to perform a POST request to Microsoft Graph. The various properties of the new team are set in the body. In order to easily copy these properties, I also have them as text below the image. Note that if you have renamed the variables and/or actions, you will also have to adjust them when copying the body-text.

HTTP request to Microsoft Graph to create the new team
{
  "template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates/standard",
  "displayName": "@{variables('StrTeamStart')}@{body('Get_response_details')?['r4a6d0d326bfd43e3b47e9959bac1dd26']}",
  "description": "@{body('Get_response_details')?['r9d583ab44ac54742a785ba6738f1a3ac']}",
  "Visibility": "Private",
  "owners@odata.bind": [
    "https://graph.microsoft.com/v1.0/users/@{body('GetRequestersProfile')?['id']}"
  ],
  "memberSettings": {
    "allowCreateUpdateChannels": true,
    "allowDeleteChannels": true,
    "allowAddRemoveApps": true,
    "allowCreateUpdateRemoveTabs": true,
    "allowCreateUpdateRemoveConnectors": true
  },
  "guestSettings": {
    "allowCreateUpdateChannels": false,
    "allowDeleteChannels": false
  },
  "funSettings": {
    "allowGiphy": true,
    "giphyContentRating": "Moderate",
    "allowStickersAndMemes": true,
    "allowCustomMemes": true
  },
  "messagingSettings": {
    "allowUserEditMessages": true,
    "allowUserDeleteMessages": true,
    "allowOwnerDeleteMessages": true,
    "allowTeamMentions": true,
    "allowChannelMentions": true
  }
}

To make the flow more beautiful, there are a lot of extra options that I have added eventually. But for the overview I leave it at this. But for example consider:

  • An approval process
  • Keep a log of what is being requested and the status of approval
  • Offer different team templates in your form and take them into account when creating the team
  • Send a confirmation to the applicant
  • Post a welcome message to the new team or a video about how to use MS Teams
  • A check to build in if the team does not already exist
  • Put all the input into variables like I descriped in this blog.

An overview of the complete flow:

Overview of the flow for creating a new team