- Configure automatic reply message in Exchange with PowerShell or ECP - Mon, Jul 5 2021
- Create and manage Exchange distribution groups with PowerShell - Wed, Jan 13 2021
- Manage Microsoft Teams with PowerShell: Create and configure teams, add users - Mon, Oct 12 2020
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.
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\*
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:
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
Creating and changing teams ^
You can create a new team using the following command:
New-Team -DisplayName MyTeam -Description "My new team" -Visibility Public
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>
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.
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!
This command is useful for automation, such as removing teams that no longer have an owner or have no remaining members.