Skip to content

/commands/teams/get-team-new-team

Get-Team and New-Team: list and create Microsoft Teams teams with PowerShell

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
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:

powershell
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 Owner

New-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:

powershell
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 Role

Output

New-Team -Visibility: Public, Private, HiddenMembership
New-Team -Template: EDU_Class, EDU_PLC
Add-TeamUser -Role: Owner, Member
VisibilityMeaning
PrivateOwners approve or add members
PublicAnyone in the organization can join
HiddenMembershipMembership 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

ParameterUse
-MailNickNameMail alias of the group; generated from the display name if omitted
-OwnerOwner when an admin creates the team for someone else; mandatory with certificate (app-only) sign-in
-GroupIdTurn 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:

ParameterWhat it filters
-DisplayNameTeams whose display name matches the text
-MailNickNameThe team by its group mail alias
-GroupIdOne team by its Microsoft 365 group ID (fastest, exact)
-UserTeams the given user belongs to (UPN)
-ArchivedOnly archived ($true) or only active ($false) teams
-VisibilityPublic or Private teams (not validated, see above)
-NumberOfThreadsThreads 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 Hidden is 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 -DisplayName can return several teams. Store and reuse the GroupId in scripts.
  • Owner leaves. A team should keep at least two owners; add a second one with Add-TeamUser -Role Owner right after creation, as in the first example.
  • Archiving versus deleting. Set-TeamArchivedState makes a team read-only and keeps it, while Remove-Team deletes 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.

Sources