Control Microsoft Teams using PowerShell

Explains how to install powershell module for MicrosoftTeams and how we can manage the MicrosoftTeams using PowerShell commands.

Microsoft Teams is a chat based workspace for Office 365 – Microsoft

It is one of the emerging application in Office 365, which helps to bring the people in to a single place for collaborate content, conversations, people and more…

We can handle the Microsoft Teams through browser and client-based Microsoft Teams application. We also have Microsoft Graph API to manage the Microsoft Teams by managing teams, channels, members and more.

As a developer Microsoft Graph API will make their life easier, but for IT professional it is difficult to control the Teams application. To help them, Microsoft have come up with a PowerShell Module to control the Microsoft Teams.

To get the PowerShell Module to our local environment, we have get the MicrosoftTeams module from PowerShell Gallery.


 

Find the MicrosoftTeams PowerShell module from the PowerShell Gallery

  • Open Windows PowerShell
  • Run the below command to find the MicrosoftTeams module

PS:> Find-Module MicrosoftTeams

Find MicrosoftTeams Module from PowerShell Gallery
Find MicrosoftTeams Module from PowerShell Gallery

 

Install MicrosoftTeams PowerShell module as an Administrator

  • Open Windows PowerShell as an Administrator
  • Then Run the below command

PS:> Install-Module MicrosoftTeams

  • Upon prompt; to trust untrusted source from PowerShell Gallery. Press ‘Y’ and then press ‘Enter

 

Install MicrosoftTeams PowerShell module as a normal user

  • Open Windows PowerShell as an Administrator
  • Then Run the below command

PS:> Install-Module MicrosoftTeams –Scope CurrentUser

  • Upon prompt; to trust untrusted source from PowerShell Gallery. Press ‘Y’ and then press ‘Enter

 

Verify the PowerShell module is installed

  • Open Windows PowerShell
  • Run the below command

PS:> Get-Module MicrosoftTeams -ListAvailable

  • If the command returns the value, then the module is installed. Otherwise we have to install the module.
Get MicrosoftTeam Module
Get MicrosoftTeam Module

 

Get the list of available cmdlets from Microsoft Teams

After the installation of Microsoft Teams PowerShell module, we can get the list of available commands available in the module to manage and control the Microsoft Teams

  • Open Windows PowerShell
  • Run the below command to get the list of commands

PS:> Get-Command –Module MicrosoftTeams

Get all available commands from MicrosoftTeams PowerShell Module
Get all available commands from MicrosoftTeams PowerShell Module
  • Also, we can run the below command to get the list of commands

PS:> Get-TeamHelp

Get all available commands from MicrosoftTeams PowerShell Module
Get all available commands from MicrosoftTeams PowerShell Module

Based on the screenshot above, below is the list of command and have linked them to the documentation for each command

Command Description
Add-TeamUser Adds an owner or member to the Team
Connect-MicrosoftTeams Connect to the Microsoft Team based on the provided credentials
Disconnect-MicrosoftTeams Disconnect from the Microsoft Team
Get-Team Returns all the teams that the user belongs to
Get-TeamChannel Returns all the channels for a Team
Get-TeamFunSettings Returns a team’s fun settings
Get-TeamGuestSettings Returns Team guest settings
Get-TeamHelp Returns a list of commands for Microsoft Teams
Get-TeamMemberSettings Returns team member settings
Get-TeamMessagingSettings Returns team messaging settings
Get-TeamUser Returns all users from the team
New-Team Creates a new team
New-TeamChannel Add a new channel to the team
Remove-Team Deletes a Team
Remove-TeamChannel Deletes a channel and this will not delete the content from associated tabs
Remove-TeamUser Remove an owner or member from the team.
Last owner cannot be removed from the team
Set-Team Updates a team properties
Set-TeamChannel Updates a team channel settings
Set-TeamFunSettings Update Giphy, Stickers and Memes settings
Set-TeamGuestSettings Updates team guest settings
Set-TeamMemberSettings Updates team member settings
Set-TeamMessagingSettings Updates team messaging settings
Set-TeamPicture Updates the team picture

 

Connect Microsoft Team:

  • Open Windows PowerShell
  • Enter the below command to connect with Microsoft Teams

PS:> Connect-MicrosoftTeams

Connecting MicrosoftTeam
Connecting MicrosoftTeam

To get the Teams available for the current user:

  • Open Windows PowerShell and ensure MicrosoftTeams module is installed.
  • Run the below command to get the Teams associated to the current user

PS:> $cred = Get-Credential
PS:> Connect-MicrosoftTeams –Credential $cred
PS:> Get-Team

Get all Teams associated to the User
Get all Teams associated to the User

To create a new Team

Below is the syntax used for creating a new team,

New-Team -DisplayName <String> [-Description <String>] [-Alias <String>] [-Classification <String>] [-Visibility <String>] [-DontAddMeAsMember <Boolean>]

 

Property Mandatory
DisplayName Yes
Description No
Alias No
Classification No
Visibility No
DontAddMeAsMember No

Use the below steps to create a new Team,

  • Open Windows PowerShell and ensure MicrosoftTeams module is installed
  • Run the below command to create a new Team

PS:> $cred = Get-Credential

PS:> Connect-MicrosoftTeams –Credential $cred

PS:> New-Team –DisplayName <NewTeamName>

  • It creates a new Team with default owner as a created User. And it also creates the Office 365 group, SharePoint Online Site Collection, Planner.
Create a Team using PowerShell
Create a Team using PowerShell

 

Update settings to the Team

Below is the syntax for updating the property to the Microsoft Team,

Set-Team -GroupId <String> [-DisplayName <String>] [-Description <String>] [-Alias <String>] [-Classification <String>] [-AccessType <String>]

Property Mandatory
GroupId Yes
DisplayName No
Description No
Alias No
Classification No
AccessType  [Public | Private] No

The following step used to change the display name for the Team,

  • Open Windows PowerShell and ensure MicrosoftTeams module is installed
  • Run the below command to change the display name for the TestPowerShell Team

PS:> $cred = Get-Credential

PS:> Connect-MicrosoftTeams –Credential $cred

PS:> Set-Team –GroupId <Team’s Group Id> –DisplayName <NewTeamName>

  • It changes the TestPowerShell Team name to PowerShellTeam and you can find the update below,
Update a Team using PowerShell
Update a Team using PowerShell

 

Delete a Team

Now, we are going to delete the team “PowerShellTeam” from the Microsoft Teams & Office 365.
Below is the syntax to remove the team from the Microsoft teams
Remove-Team -GroupId <String>

  • Open Windows PowerShell
  • Run the below command to delete the Team from the Microsoft team

PS:> $cred = Get-Credential

PS:> Connect-MicrosoftTeams –Credential $cred

PS:> Remove-Team -GroupId <Team’s Group Id>

  • The code removes the Team from Microsoft team and also removes the associated Office 365 Group, SharePoint Online Team Site Collection and Plan from Microsoft Planner.
Delete a Team using PowerShell
Delete a Team using PowerShell

Summary:

The PowerShell module for Microsoft Teams is in initial stage and currently it contains the basic commands to do basic options. Lot more commands are yet to come, so keep your eye on the documentation for each commands are available in  the GitHub. I’ll bring  with details on other commands in my next article. So stay tuned…

Shantha Kumar
Shantha Kumar
Articles: 278

24,849 Comments

  1. Very useful module, thanks to point to it.
    I hope the development team (!) will include a possibility to list all teams for a tenant not just the user belong to.
    As a global admin I’m not very interested by my membership but all team groups.

  2. Hi Shantha Kumar,

    I want to Mute Audio/Video using power shell cmdlets command.
    Please suggest.

    Thanks
    Sarvjeet

Comments are closed.