Learn how to use the New-MgTeam cmdlet in Microsoft Graph PowerShell to create Microsoft Teams with properties like display name, description, and visibility. Includes examples for single and bulk creation.
The New-MgTeam cmdlet is a powerful tool for creating and managing Microsoft Teams through PowerShell. This article provides a detailed guide on using this cmdlet, including syntax, usage examples, tips, and solutions to common errors.
Install-Module Microsoft.Graph -Scope CurrentUser
.Connect-MgGraph -Scopes "Group.ReadWrite.All"
.New-MgTeam -BodyParameter <hashtable>
The command for creating a team with only basic details like DisplayName, Description, Visibility and the team template.
$team = @{
DisplayName = "Team Name"
Description = "This is a sample team"
Visibility = "Public"
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
}
New-MgTeam -BodyParameter $team
The command for creating a team with specific member settings, guest settings, messaging settings and fun settings.
$team = @{
DisplayName = "Team Name"
Description = "This is a sample team with specific settings"
Visibility = "Private"
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
MemberSettings = @{
AllowCreateUpdateChannels = $true
AllowDeleteChannels = $false
}
GuestSettings = @{
AllowCreateUpdateChannels = $false
AllowDeleteChannels = $false
}
MessagingSettings = @{
AllowUserEditMessages = $true
AllowUserDeleteMessages = $false
}
FunSettings = @{
AllowGiphy = $true
GiphyContentRating = "Moderate"
}
}
New-MgTeam -BodyParameter $team
The command for creating multiple teams by reading data from CSV files. Ensure your CSV files contain the following headers.
Example CSV File:
DisplayName,Description,Visibility
Team1,Description for Team1,Private
Team2,Description for Team2,Public
PowerShell script to create teams from the CSV file:
$teams = Import-Csv -Path "C:\path\to\teams.csv"
foreach ($team in $teams) {
$teamParams = @{
DisplayName = $team.DisplayName
Description = $team.Description
Visibility = $team.Visibility
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
}
New-MgTeam -BodyParameter $teamParams
}
You can also create a team from an existing Microsoft 365 group by passing the Group Id to group@odata.bind parameter.
$params = @{
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
"group@odata.bind" = "https://graph.microsoft.com/v1.0/groups('your-group-id')"
}
New-MgTeam -BodyParameter $params
Replace 'your-group-id' with the actual ID of the Microsoft 365 Group you want to convert into a team. You can get the group ID using the Get-MgGroup cmdlet.
Including error handling with a try-catch block within the script will help you catch errors easily.
try {
$team = @{
DisplayName = "Error Handling Team"
Description = "Team with error handling"
Visibility = "Private"
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
}
New-MgTeam -BodyParameter $team
} catch {
Write-Error "Failed to create team: $_"
}
template@odata.bind
property is crucial for specifying the type of team template to use.Error | Cause | Solution |
Permission Denied | You don't have the permission to perform the required action. | You need to be a Teams Administrator and have sufficient Graph API permissions like Group.ReadWrite.All. |
Invalid Group ID | Provided Group ID does not exist or is wrong. | Check whether the group ID exists or not using Get-MgGroup cmdlet. |
API Rate Limits | You have exceeded the API rate limits. | Implement API throttling coding logic. |
$Body = @{
displayName = "New Team Name"
description = "This is a new team."
visibility = "Private"
memberSettings = @{
allowCreateUpdateChannels = $true
}
}
New-MgTeam -BodyParameter $Body
DisplayName,Description,Visibility
Team 1,Description for Team 1,Private
Team 2,Description for Team 2,Public
Use this script to process the CSV and create teams:$Teams = Import-Csv -Path "C:\Path\To\File.csv"
foreach ($Team in $Teams) {
$Body = @{
displayName = $Team.DisplayName
description = $Team.Description
visibility = $Team.Visibility
}
New-MgTeam -BodyParameter $Body
}
New-MgTeam
supports both scenarios:
group@odata.bind
property"https://graph.microsoft.com/v1.0/groups('GROUP-ID')"
memberSettings
, messagingSettings
, and funSettings
Are Optional But UsefulThe New-MgTeam cmdlet is a versatile tool for creating Microsoft Teams with various configurations. Whether creating a simple team, setting specific permissions, or bulk creating teams from a CSV file, this cmdlet provides the flexibility needed to manage teams effectively. By following the examples and tips provided, you can streamline your team creation process and handle potential errors efficiently.
© m365corner.com. All Rights Reserved. Design by HTML Codex