Create a company-wide team in Microsoft Teams using PowerShell
This training provides a PowerShell script that creates a public, company-wide team in Teams. The script uses the MicrosoftTeams PowerShell module (currently in beta) to create a public, company-wide team. It also uses the AzureAD PowerShell module to fetch the list of users in your tenant.
This is a great starting point if you want to dabble in some simple PowerShell commands and familiarize yourself with this powerful enterprise tool. PowerShell is a key component in management of other aspects of AzureAd Groups, including group-creation control - which is how to manage who can create a team in Teams.
This PowerShell script adds only the first 2500 members to a team. 2500 is the current team size limit.
This training is for IT admins or Teams users who want to automate team creation. You'll learn how to:
- Install the relevant modules in PowerShell
- Use the script
We won't cover these things:
- A deep dive into PowerShell. We only include the PowerShell information you need to get up and running with the PowerShell script. To learn more, start at Getting Started with Windows PowerShell
- The functionality of the AzureAD module. This PowerShell script uses the AzureAD module for a single command to fetch the users in the tenant.
- The cmdlets in the MicrosoftTeams module.
- A line-by-line walk-through of the PowerShell script.
To ask questions or send feedback about this training:
You'll need to have Administrator permissions on your computer, so you can run applications as administrator.
The modules that we use in this script require one of the following operating systems:
- Windows 10
- Windows 8.1 Pro
- Windows 8.1 Enterprise
- Windows 7 SP1
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2008 R2 SP1
The modules also require .NET Framework 4.5 or above. Install the .NET Framework for developers.
To get started, you'll need the following:
A trial version of Office 365 Enterprise E3. We recommend testing and learning in a test tenant before starting to work in your actual tenant. Add some test users to your tenant (minimum 5) to help you play around with the script.
Launch PowerShell with administrator privileges. Here's how to do it in Windows 10:
a. Click Start.
b. Type Windows PowerShell.
c. Right-click and choose Run as administrator.
You may get prompted to update your NuGet provider by PowerShellGet during the execution of these steps. If you get prompted, choose Yes for "Do you want PowerShellGet to install and import the NuGet provider now?" You may also get prompted about an untrusted repository: "Are you sure you want to install the modules from 'PSGallery?'" Choose Yes here as well.
Install the MicrosoftTeams PowerShell module. If you've met all the conditions to install the AzureAD module, installing the MicrosoftTeams module will go quickly (they share the same set of conditions). To install the MicrosoftTeams module, run this command:
You may get prompted about the untrusted repository again.
All the parameters are set as optional, but the script won't run if none of the parameters are set. You'll use a combination of parameters to create and update your company-wide team. We'll show you samples in a later section to help you execute the script based on your scenario.
|Owners||Specify at least two members (one of the two can be you but the script requires a minimum of two). We recommend more owners especially for the tenant wide team.|
|TeamName||Specify this if you intend to create a new team. If this isn't specified, you must specify the GroupId of an existing team.|
|TeamDescription||This is the description for the new team you are creating. It won't update an existing team's description.|
|Channels||List of channels you want to create. This script requires at least two channels (if you use this parameter). When the script runs, it'll ask you for each channel's description.|
|GroupId||Specify this if you have an existing team that you want to make into a company-wide team by adding more members. If you specify this parameter, a new team does not get created.|
|Members||You can specify a list of members if don't want everyone to get added. Minimum number in the list is 2.|
Run the script
The script provided is an unsigned script. Read About Execution Policies to learn more. Before changing the execution policy, fetch the current policy by running the following command:
Note this policy level. You'll change it back to this level once you're done running this script to create your company-wide team. To change the policy to RemoteSigned, run this command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Here's what you can do using the script:
Create a new team with all the members in your tenant (maximum 2500 members).
.\CreateCompanyWideTeam.ps1 -Owners "CBeane@Contoso.onmicrosoft.com", "PHampton@Contoso.onmicrosoft.com" -TeamName "Contoso Team" -TeamDescription "Tenant wide team to get everyone into one place. Use this team to share announcements, hold townhalls, or just encourage a more open work environment for everyone" -Channels "Announcements", "Townhalls"
Add all the members in your tenant to an existing team (maximum 2500 members).
.\CreateCompanyWideTeam.ps1 -GroupID "45f7b85e-149b-4ae4-bf43-9cedf9415e34"
Add a specified set of members to a new or existing team.
.\CreateCompanyWideTeam.ps1 -Owners "CBeane@Contoso.onmicrosoft.com", "PHampton@Contoso.onmicrosoft.com" -TeamName "Project Scorpio" -TeamDescription "Wanted to reserve a cool project name, now we need a project" -Channels "Code Reviews", "Engineering Alerts" -Members "BMcMillan@Contoso.onmicrosoft.com", "DTodd@Contoso.onmicrosoft.com", "DMills@Contoso.onmicrosoft.com"
Sample company-wide team
Here's a table showing how you might set up a team for a sales company. It includes suggested channels, tabs, connects, and bots. We recommend that, at least initially, you create a couple of channels. If this is the first team that many people will be a part of, it'll help them understand what kind of channels to create. Seeding some of these initial channels with data will also help new users get familiar with the product and understand this working style. For now, you can't add data to channels using PowerShell, so you'll have to do this part manually.
Download our Microsoft Teams getting started kit. This guide includes "The first 10 things to do in Teams." You’ll find tips to make the most of Teams for various functions in your organization, including Marketing, Sales, Finance, Human Resources, Information Technology, Engineering, and Project Management.
🏆 Best practices:
- Don't create every channel you can think of at this stage, just enough to get the ball rolling. Keep creating channels as new areas arise.
- Don't rename channels, because the underlying SharePoint folder structure won't continue to align with the channel name.
Deleted channels can't be recreated with the same name, but you can still find the SharePoint files.
The table below outlines a sample team with some suggested tabs, connectors, and bots. It's definitely not a complete list, just enough to give you an idea of what kind of channels could be useful for your company.
|Channel||Tabs & resources|
|Product updates & feedback||
|Teamwork at Contoso||
|Water cooler talk||
Watch our video, Tech Tip: Guidance for Setting Up Teams, Channels and Tabs (4 minutes), to learn best practices for setting up your teams, channels, and tabs for maximum productivity.
Script at a glance
There are 5 sections to this script (listed in order from top to bottom):
- Documentation and variable definitions
- Function Create-Team: Creates a team if necessary. If you don't specify a GroupID, this section will create the team with the specified TeamName and TeamDescription.
- Function Add-Channels: If you've specified channels, this is where the channel description gets requested, and then the channel gets created.
- Function Add-Members: This does all member management. This section connects to AzureAD, fetches a set of users, and adds them to the team if you don’t provide a member list. It handles the logic of adding owners and members, and not adding members who already belong to the team.
- Main program: This is the order in which the functions get executed.
Call to action
Plan your company-wide team if you don't already have an existing team that can fill this role. Figure out the name, description, required owners, and useful initial channels.
Test the script using your parameters in your test tenant. Add some sample content, and make sure it looks good.
Run the script to create the team in your tenant. Alternatively, you can manually create the team through the Teams UI, seed all the data (channels, bots, apps, connectors) then leverage the script just to add all the owners and members. To see a list of teams you've created and their groupIDs use:
Then use this GroupID and run the script specifying more owners:
.\CreateCompanyWideTeam.ps1 -GroupID "45f7b85e-149b-4ae4-bf43-9cedf9415e34" -Owners "CBeane@Contoso.onmicrosoft.com", "PHampton@Contoso.onmicrosoft.com"
Now when people enter this team, they already have an idea of what else they can pin, connect, or chat about.
Send us feedback
- Give us feedback, or ask questions, about this training in the Comments section at the bottom of this page
- To give us Teams product feedback or to request a new feature, go to Teams UserVoice