End users can mostly manage Microsoft Teams themselves, but the IT department still has some administrative and supporting tasks to cope with. As with all other Microsoft 365 services, there is a dedicated PowerShell module that allows administrators to automate many tasks.

In the first step, as with most external services and applications, you have to add the appropriate PowerShell module to the system. For Teams, the command used to do this is as follows:

Install-Module -Name MicrosoftTeams

To install the module, you may need to agree to update your NuGet provider and confirm that you want to download from an unsafe source. PSGallery is still not considered trustworthy.

Installation of the PowerShell module for Microsoft Teams from PSGallery

Installation of the PowerShell module for Microsoft Teams from PSGallery

Occasionally, the following error may occur:

Unable to resolve package source 'https://powershellgallery.com/api/v2'.

This is usually because PowerShell Gallery no longer accepts connections with TLS 1.0 and 1.1. Some versions of PowerShell still use them by default. I was able to solve the problem by configuring the registry keys with the following commands:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' `
-Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' `
-Name 'SchUseStrongCrypto' -Value '1' -Type DWord

In this case, you need to restart PowerShell and run the Install-Module command again.

To verify the success of the installation and get an overview of the available cmdlets, you can issue this command:

Get-Command -Module MicrosoftTeams\*
List of cmdlets included in the PowerShell module for Teams

List of cmdlets included in the PowerShell module for Teams

Currently, the list contains 32 cmdlets or functions.

Connecting to Teams ^

As with PowerShell for Exchange and other online services from Microsoft, you have to connect to Teams first before you can manage them via scripts. For this purpose, enter the following command:

Connect-MicrosoftTeams
Connect to Teams using the Connect MicrosoftTeams cmdle

Connect to Teams using the Connect MicrosoftTeams cmdle

Logging on to the tenant is possible with or without multi-factor authentication (MFA).

Show existing teams ^

With the following command, you get an initial overview of the teams that have already been created:

Get-Team | Format-List
View existing teams with PowerShell

View existing teams with PowerShell

Creating and changing teams ^

You can create a new team using the following command:

New-Team -DisplayName MyTeam -Description "My new team" -Visibility Public
Creating a new team using PowerShell

Creating a new team using PowerShell

Corresponding to the options available in the Teams client, you can pass several parameters to the cmdlet.

If you want to change the settings of a team afterward, you can do this using Set-Team.

It essentially supports the same parameters as New-Team, so you can use it to subsequently change or add values to the properties of a team if you did not configure them when you first created it.

In this example, I will just change the name of the team:

Set-Team -GroupId <GroupID> -DisplayName <new-name>
Renaming team using Set Team

Renaming team using Set Team

As you can see, you refer to a certain team using the parameter GroupId.

Adding members ^

Members can be added when creating a team with New-Team or later on with Add-TeamUser. Conversely, you can remove them again with Remove-TeamUser.

Add members to an existing team

Add members to an existing team

Get-TeamUser then displays all users of a team, whereby the latter is again specified via the GroupId.

Deleting teams ^

If the team is no longer needed and should, therefore, be deleted, it can be done using the following command:

Subscribe to 4sysops newsletter!

Remove-Team
Deleting a Team via PowerShell

Deleting a Team via PowerShell

This command is useful for automation, such as removing teams that no longer have an owner or have no remaining members.

avataravatar
1 Comment
  1. Jose 8 months ago

    Hi is it needed to have admin privileges? Or just owner of a team. Thank you!

Leave a reply to Jose Click here to cancel the reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account