Create Microsoft Teams Using Graph PowerShell
The New-MgTeam Graph PowerShell cmdlet creates Microsoft team. Let understand how New-MgTeam can be used to create:
- Single Microsoft Team
- Multiple Microsoft Teams using Powershell array and CSV files
- Microsoft Team with multiple channels and,
- Microsoft Team from existing M365 group
Prerequisites
- You need to install the Microsoft Graph PowerShell SDK. Install-Module Microsoft.Graph -Scope CurrentUser is the command.
- You need to connect to the Microsoft Graph PowerShell Module with the necessary permissions. Connect-MgGraph -Scopes "Group.ReadWrite.All", "Directory.ReadWrite.All" is the command.
Create Microsoft Team
Here's how you can create a single Microsoft Team using New-MgTeam cmdlet.
Here's how the script works:
- Import-Module Microsoft.Graph.Teams
-
This command loads the Microsoft Graph Teams module into the current PowerShell session. It's necessary to have this module available to use the cmdlets that interact with Microsoft Teams through the Microsoft Graph API.
- $params = @{ ... }
-
This section creates a PowerShell hashtable named $params that stores the parameters used to configure the new team. Hashtables are key-value pairs in PowerShell and are often used to pass a set of parameters to cmdlets.
- Inside this hashtable:
- "template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')": This line specifies the template to use when creating the team. Here, a standard template is used, which sets up a basic team structure.
- displayName = "My Sample Team": Sets the display name of the team.
- description = "My Sample Team’s Description": Provides a description for the team.
- New-MgTeam -BodyParameter $params
- This command creates a new team in Microsoft Teams using the parameters defined in $params.
- -BodyParameter: This parameter of New-MgTeam cmdlet takes a hashtable or an object that contains the body of the request to be sent to Microsoft Graph. Here, it takes $params which includes all the necessary details to create the team as specified.
Create Multiple Microsoft Teams
To create multiple Microsoft Teams using an array of team IDs directly within the script, you can define an array of hashtables where each hashtable contains the specific properties (like DisplayName and Description) for each team.
Here's how the script works:
- Import-Module: Loads the Microsoft Graph Teams module to access Microsoft Graph API functions.
- $teams Array: Defines an array of hashtables. Each hashtable contains DisplayName and Description for a team.
- foreach Loop: Iterates over each element in the $teams array. For each team, it sets up the required parameters and creates the team using New-MgTeam.
This script is versatile and straightforward. It allows you to easily add more teams to the array by defining additional hashtables. Each time the script runs, it will create all the teams listed in the $teams array.
This method is great for situations where you don’t have a large number of teams or don't need to read from external sources like CSV files. You can modify each team’s properties directly in the script, which might be more manageable for smaller sets or for testing purposes.
Create Microsoft Teams From CSV File
This script is designed to create multiple teams in Microsoft Teams using data provided in a CSV file. Each row in the CSV corresponds to a team, and each column contains properties used to define that team.
Here's how the script works:
- Import-Module Microsoft.Graph.Teams
-
This command loads the Microsoft Graph Teams module into the current PowerShell session. It's necessary to have this module available to use the cmdlets that interact with Microsoft Teams through the Microsoft Graph API.
- Load Team Data from a CSV File
$teamData = Import-Csv -Path "path_to_your_csv_file.csv"
-
Import-Csv reads data from a CSV file at the specified path. The CSV should have at least two columns: DisplayName and Description. Each row in the CSV file represents a different team to be created.
- $teamData will store an array where each element is a custom object created from a row in the CSV file. The properties of these objects (DisplayName, Description) are accessible via dot notation, e.g., $team.DisplayName.
- Loop Through Each Team in the CSV Data
foreach ($team in $teamData) {
...
}
- The foreach loop iterates over each element in $teamData. Each iteration processes a single team's data.
- $team is a variable representing the current team being processed. It has properties corresponding to the columns in the CSV file.
-
Prepare Parameters for Creating a New Team
$params = @{
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
displayName = $team.DisplayName
description = $team.Description
}
- $params is a hashtable storing the parameters needed to create a team via the Graph API.
- "template@odata.bind": Specifies the URL of the team template to use (standard in this case), which defines some of the basic structure and settings for the new team.
- displayName and description: Set from the current $team object, specifying the name and description of the new team.
-
Create the Team
New-MgTeam -BodyParameter $params
- New-MgTeam is the cmdlet that actually creates a team in Microsoft Teams using the Microsoft Graph API.
- -BodyParameter: This parameter passes the hashtable $params which includes all necessary information to create the team as defined by the Graph API.
Create Microsoft Teams With Multiple Channels
This PowerShell script creates a new team in Microsoft Teams with multiple channels.
Here's how the script works:
- Import-Module Microsoft.Graph.Teams
-
This command loads the Microsoft Graph Teams module into the current PowerShell session. It's necessary to have this module available to use the cmdlets that interact with Microsoft Teams through the Microsoft Graph API.
- Setting up Parameters: Here, $params is a hash table that holds the parameters needed to create the new team:
-
"template@odata.bind": Specifies the URL of the template used to create the team. 'standard' template is a predefined template provided by Microsoft.
- visibility: Sets the team's visibility to Private, meaning only invited members can see the team.
- displayName: The name of the team
- description: A brief description of what the team is about
- The channels key contains an array of hash tables, each representing a channel to be created in the team:
-
displayName: Name of the channel.
- `isFavoriteByMultipleLine
- description: Description of what the channel is for.
- Defining Channels
The channels key in the $params hash table contains an array of hash tables, each defining a channel:
-
Announcements 📢 Channel: Marked as a favorite by default, intended for important announcements.
- Training 🏋️ Channel: Also a favorite by default, includes resources like pinned websites and YouTube tabs.
- Planning 📅 Channel: Not a favorite by default, appears in the overflow menu for more channels.
- Issues and Feedback 🐞 Channel: Similar to the Planning channel in its setup.
Each channel can have properties such as displayName, isFavoriteByDefault, and description to determine how they appear and behave in the team.
-
Creating the Team
New-MgTeam -BodyParameter $params
This command uses the New-MgTeam cmdlet with the $params hash table as input to create a new team based on the specified parameters. The BodyParameter parameter passes the structured information necessary to configure the team and its channels according to the specifications in $params.
Create Microsoft Team From Existing M365 Group
Here how you can create a team from an existing Microsoft 365 group.
Here's how the script works:
- Import-Module Microsoft.Graph.Teams
-
This command loads the Microsoft Graph Teams module into your PowerShell session. This module includes cmdlets for managing Teams-related resources through Microsoft Graph API.
- Define Parameters:: Here, you are creating a hashtable called $params that contains the parameters for creating a new team.
-
"template@odata.bind": Specifies the template used for creating the team. In this case, it uses the 'standard' template provided by Microsoft, which sets up a typical team with a general set of features and channel structures.
- "group@odata.tabsind": Specifies the Office 365 group to which the team will be linked. The ID provided ('71392b2f-1765-406e-86af-5907d9bdb2ab') must be an existing group within your organization.
- Create the New Team:
New-MgTeam -BodyParameter $params
This command actually creates the new team using the Microsoft Graph API. It takes the $params hashtable as input through the -BodyParameter parameter. This tells the API to create a new team with the settings specified in $master.
Related Articles:
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell