Control Microsoft Teams Using PowerShell

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

It is one of the emerging applications in Office 365, which helps to bring people to a single place for collaborating on content, conversations, connecting with people, and more…

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

Microsoft Graph API makes the lives of developers easier, but for IT professionals, it is difficult to control the Teams application. To help them, Microsoft has come up with a PowerShell Module to control the Microsoft Teams.

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

Find the MicrosoftTeams PowerShell module from the PowerShell Gallery

  • Open Windows PowerShell.
  • Run the “Find-Module MicrosoftTeams” command.

    PowerShell

Install Microsoft Teams PowerShell module as an Administrator

  • Open Windows PowerShell as an Administrator
  • Then, run the below command

    PS:> Install-Module MicrosoftTeams
  • Upon prompt; to trust the untrusted source from PowerShell Gallery, press ‘Y’ and then press ‘Enter’.

Install Microsoft Teams 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 the 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.

    PowerShell

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

    PowerShell
  • Also, we can run the below command to get the list of commands

    PS:> Get-TeamHelp

    PowerShell

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

CommandDescription
Add-TeamUserAdds an owner or member to the Team
Connect-MicrosoftTeamsConnect to the Microsoft Team based on the provided credentials
Disconnect-MicrosoftTeamsDisconnect from the Microsoft Team
Get-TeamReturns all the teams that the user belongs to
Get-TeamChannelReturns all the channels for a Team
Get-TeamFunSettingsReturns a team's fun settings
Get-TeamGuestSettingsReturns Team guest settings
Get-TeamHelpReturns a list of commands for Microsoft Teams
Get-TeamMemberSettingsReturns team member settings
Get-TeamMessagingSettingsReturns team messaging settings
Get-TeamUserReturns all users from the team
New-TeamCreates a new team
New-TeamChannelAdd a new channel to the team
Remove-TeamDeletes a Team
Remove-TeamChannelDeletes a channel and this will not delete the content from associated tabs
Remove-TeamUserRemove an owner or member from the team. The last owner cannot be removed from the team
Set-TeamUpdates a team properties
Set-TeamChannelUpdates a team channel settings
Set-TeamFunSettingsUpdate Giphy, Stickers and Memes settings
Set-TeamGuestSettingsUpdates team guest settings
Set-TeamMemberSettingsUpdates team member settings
Set-TeamMessagingSettingsUpdates team messaging settings
Set-TeamPictureUpdates the team picture

Connect Microsoft Team

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

    PS:> Connect-MicrosoftTeams


    PowerShell

To get the Teams available for the current user

  • Open Windows PowerShell and ensure that the 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

PowerShell

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>]

PropertyMandatory
DisplayNameYes
DescriptionNo
AliasNo
ClassificationNo
VisibilityNo
DontAddMeAsMemberNo

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>

PowerShell

  • 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.

    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>]

PropertyMandatory
GroupIdYes
DisplayNameNo
DescriptionNo
AliasNo
ClassificationNo
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>

PowerShell 

  • It changes the TestPowerShell Team name to PowerShellTeam and you can find the update below.

    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>

PowerShell

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

Summary

The PowerShell module for Microsoft Teams is in the 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 command which are available on GitHub. I’ll bring out the details of other commands in my next article. So stay tuned…