The Microsoft Teams PowerShell module is designed to manage Teams from the command line. You can use the Teams module commands to quickly perform common administrative tasks or in automation scenarios. In this article, we will show how to install the Teams PowerShell module and look at typical commands a Microsoft 365 administrator may need to manage Teams.
How to Install Microsoft Teams PowerShell Module?
To install the Microsoft Teams module, you must have PowerShell 5.1 or newer installed on your computer. You can check the current PowerShell version using the command below:
$PSVersionTable.PSVersion
If necessary, update your PowerShell version.
You can install the MS Teams module from the PowerShell Gallery using this command:
Install-Module -Name MicrosoftTeams
To make sure that the Teams module is installed on your computer and display its version, run the command below:
Get-Module MicrosoftTeams –ListAvailable
You can install a specific Teams module version from PSGallery. List available module versions:
Find-Module MicrosoftTeams -AllVersions
To install a specific version, run the command:
Install-Module -Name MicrosoftTeams -RequiredVersion 4.5.0
To update the MS Teams PowerShell module:
Update-Module -Name MicrosoftTeams
You can display a full list of cmdlets in the module:
Get-Command –Module MicrosoftTeams
How to Manage Microsoft Teams Using PowerShell Module?
To connect to your Teams tenant in Microsoft 365 use this command:
Connect-MicrosoftTeams
Enter your user name and password. If the user’s Azure account has MFA enabled, you need to confirm your sign-in.
- Global Admin
- Teams Service Admin
- Teams Communications Admin
- Teams Communications Support Engineer
- Teams Communications Support Specialist
To display all teams in your tenant:
Get-Teams
To create a new private team in Teams:
New-Team –DisplayName SysOps
To display all team settings:
get-team -DisplayName sysops|fl
GroupId : xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx InternalId : [email protected] DisplayName : SysOps Description : SysOps Wiki Team Visibility : Public MailNickName : msteams_xxx12a Classification : Archived : False AllowGiphy : True GiphyContentRating : moderate AllowStickersAndMemes : True AllowCustomMemes : True AllowGuestCreateUpdateChannels : False AllowGuestDeleteChannels : False AllowCreateUpdateChannels : True AllowCreatePrivateChannels : True AllowDeleteChannels : True AllowAddRemoveApps : True AllowCreateUpdateRemoveTabs : True AllowCreateUpdateRemoveConnectors : True AllowUserEditMessages : True AllowUserDeleteMessages : True AllowOwnerDeleteMessages : True AllowTeamMentions : True AllowChannelMentions : True ShowInTeamsSearchAndSuggestions : True
You can change the team description and visibility:
get-team -DisplayName sysops| Set-Team -Description "SysOps Wiki" -Visibility "Public"
To change a team picture:
get-team -DisplayName sysops | Set-TeamPicture -ImagePath c:\ps\corp_sysops.png
To add a user to the team:
get-team -DisplayName sysops| Add-TeamUser -User [email protected]
To add a team owner:
get-team -DisplayName sysops| Add-TeamUser -User [email protected] -Role Owner
You can add a user to all teams in your tenant using a simple PowerShell script:
$AllTeams = Get-Team
$UserToAdd = "[email protected]"
ForEach ($Team in $AllTeams)
{
Write-Host "Adding to $($Team.DisplayName)"
Add-TeamUser -GroupId $Team.GroupID -User $UserToAdd -Role Member
}
To display a list of users and owners of a team:
get-team -DisplayName sysops|Get-TeamUser
To display members of all Teams groups and their owners:
$AllTeams = (Get-Team).GroupID
TeamList = @()
Foreach ($CurTeam in $AllTeams)
{ $TeamGUID = $CurTeam.ToString()
$TeamName = (Get-Team | ?{$_.GroupID -eq $CurTeam}).DisplayName
$TeamOwner = (Get-TeamUser -GroupId $CurTeam | ?{$_.Role -eq 'Owner'}).Name
$TeamMember = (Get-TeamUser -GroupId $CurTeam | ?{$_.Role -eq 'Member'}).Name
$TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMembers = $TeamMember -join ', '}
}
$TeamList |fl
To remove a user from team owners and from a team:
get-team -DisplayName sysops| Remove-TeamUser -User [email protected] -Role Owner
get-team -DisplayName sysops| Remove-TeamUser -User [email protected]
To create a new private channel in an existing team, run the command below:
get-team -DisplayName sysops| New-TeamChannel -DisplayName "Windows_Wiki" -MembershipType Private
To add a user to a channel and assign him an owner:
get-team -DisplayName sysops| Add-TeamChannelUser -DisplayName “Windows_Wiki” -User [email protected] -Role Owner
To remove a user from a channel:
get-team -DisplayName sysops| Remove-TeamChannelUser -DisplayName "Windows_Wiki" -User [email protected] -Role Owner
If a team is not active, but you want to let users view its content, you can archive the team:
get-team -DisplayName sysops|Set-TeamArchivedState -Archived $true
To remove a channel:
get-team -DisplayName sysops | Remove-TeamChannel -DisplayName “Windows_Wiki”
To remove a team:
get-team -DisplayName sysops | Remove-Team
You can create a new Teams policy with New-CsTeamsMessagingPolicy:
New-CsTeamsMessagingPolicy –Identity polTeamsExternalUsers -AllowGiphy $false -AllowMemes $false –AllowUserChat $false
Identity : Tag:polTeamsExternalUsers Description : AllowUrlPreviews : True AllowOwnerDeleteMessage : False AllowUserEditMessage : True AllowUserDeleteMessage : True AllowUserDeleteChat : True AllowUserChat : False AllowRemoveUser : True AllowGiphy : False GiphyRatingType : Moderate AllowGiphyDisplay : True AllowPasteInternetImage : True AllowMemes : False AllowImmersiveReader : True AllowStickers : True AllowUserTranslation : True ReadReceiptsEnabledType : UserPreference AllowPriorityMessages : True AllowSmartReply : True AllowSmartCompose : True ChannelsInChatListEnabledType : DisabledUserOverride AudioMessageEnabledType : ChatsAndChannels ChatPermissionRole : Restricted AllowFullChatPermissionUserToDeleteAnyMessage : False AllowFluidCollaborate : False AllowVideoMessages : True
To assign a Teams policy to a user:
Grant-CsTeamsMessagingPolicy -Identity [email protected] -PolicyName polTeamsExternalUsers
Or to all users with the specific attribute in AzureAD:
Get-CsOnlineUser -Filter {Department -like '*External*'} | Grant-CsTeamsMessagingPolicy -PolicyName polTeamsExternalUsers
After you finish working in PowerShell, remember to disconnect from Microsoft Teams:
Disconnect-MicrosoftTeams