/commands/teams/get-team-new-team
Get-Team and New-Team: list and create Microsoft Teams teams with PowerShell
- tool
- Microsoft Teams PowerShell
- versions
- MicrosoftTeams 8.0.0
- os
- windows, linux, macos
After Connect-MicrosoftTeams, list teams with Get-Team and create one with New-Team:
Get-Team -DisplayName "Marketing" # filter by name
Get-Team -User anna@contoso.com # teams a user belongs to
Get-Team -Archived $true # archived teams
$team = New-Team -DisplayName "Project Phoenix" -Description "Launch planning" -Visibility Private -Owner anna@contoso.com
Add-TeamUser -GroupId $team.GroupId -User bob@contoso.com
Add-TeamUser -GroupId $team.GroupId -User carol@contoso.com -Role OwnerNew-Team returns an object with the GroupId of the new Microsoft 365 group; the other team cmdlets identify the team by that ID.
Allowed values
-Visibility and -Template of New-Team, and -Role of Add-TeamUser, accept a fixed set of values. Read from MicrosoftTeams 8.0.0 offline:
Import-Module MicrosoftTeams
function Show-Set($cmd, $param) {
$set = (Get-Command $cmd).Parameters[$param].Attributes |
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] }
'{0} -{1}: {2}' -f $cmd, $param, ($set.ValidValues -join ', ')
}
Show-Set New-Team Visibility
Show-Set New-Team Template
Show-Set Add-TeamUser RoleOutput
New-Team -Visibility: Public, Private, HiddenMembership New-Team -Template: EDU_Class, EDU_PLC Add-TeamUser -Role: Owner, Member
| Visibility | Meaning |
|---|---|
| Private | Owners approve or add members |
| Public | Anyone in the organization can join |
| HiddenMembership | Membership hidden from non-members; used for education class teams |
Get-Team -Visibility takes the same words but has no validation set in 8.0.0, so a typo returns no teams instead of an error.
Useful New-Team parameters
| Parameter | Use |
|---|---|
| -MailNickName | Mail alias of the group; generated from the display name if omitted |
| -Owner | Owner when an admin creates the team for someone else; mandatory with certificate (app-only) sign-in |
| -GroupId | Turn an existing Microsoft 365 group into a team |
| -AllowGuestCreateUpdateChannels, -AllowCreatePrivateChannels, ... | Boolean team settings |
Get-Team filters
Get-Team has seven filter parameters in MicrosoftTeams 8.0.0. Without any of them it returns every team in the tenant, which can take a long time in a large organization:
| Parameter | What it filters |
|---|---|
| -DisplayName | Teams whose display name matches the text |
| -MailNickName | The team by its group mail alias |
| -GroupId | One team by its Microsoft 365 group ID (fastest, exact) |
| -User | Teams the given user belongs to (UPN) |
| -Archived | Only archived ($true) or only active ($false) teams |
| -Visibility | Public or Private teams (not validated, see above) |
| -NumberOfThreads | Threads used to read the list (1 to 20); more threads finish faster on large tenants |
Requirements
Install the MicrosoftTeams module, then run Connect-MicrosoftTeams in the same session; both Windows PowerShell 5.1 and PowerShell 7 work. Listing and creating teams for other people needs the Teams Administrator or Global Administrator role. A normal user can create teams for themselves when the tenant allows group creation. Before you connect, Get-Team fails with Session is not established; see Connect-MicrosoftTeams for interactive, device-code and certificate sign-in.
Pitfalls
- Wrong visibility value.
New-Team -Visibility Hiddenis rejected by the validation set before anything is sent; the exact message and fix are on New-Team Visibility ValidateSet. - Duplicate names. Team display names do not have to be unique, so
Get-Team -DisplayNamecan return several teams. Store and reuse theGroupIdin scripts. - Owner leaves. A team should keep at least two owners; add a second one with
Add-TeamUser -Role Ownerright after creation, as in the first example. - Archiving versus deleting.
Set-TeamArchivedStatemakes a team read-only and keeps it, whileRemove-Teamdeletes the underlying Microsoft 365 group with its mailbox and SharePoint site.
FAQ
What permissions do I need to run New-Team for other users?
Sign in with Connect-MicrosoftTeams as a Teams Administrator or Global Administrator and pass -Owner. Without -Owner, the signed-in account becomes the owner of the new team.
Why does a team I just created not appear in the Teams client?
The New-Team help notes that the Teams application may need to be opened by an owner for up to two hours before changes are reflected. In scripts, address the team by the GroupId New-Team returned rather than searching for it by name.
How do I list the members of a team?
Use Get-TeamUser -GroupId ID, optionally with -Role Owner or -Role Member. Remove-TeamUser -Role Owner demotes an owner to member, -Role Member removes the user completely, and the last owner cannot be removed.