/ Teams

Managing Microsoft Teams with Powershell

In this post I'll play around a bit with some of the new Powershell cmdlets for managing Teams.

Setting up the environment

First of all you need the module. The easiest way is to do a simple
Install-Module MicrosoftTeams from an elevated Powershell-prompt. This will download the module from Nuget. You will get a couple of popups asking if you trust Nuget etc. Click yes.

If this doesn't work then you'll have to get it manually.

Powershell ;)

To get all the new cmdlets you need to connect to Teams (duh). This is as easy as it sounds, Connect-MicrosoftTeams. This will popup a modern authentication window, but it's also possible to pass along -Credentials.

When you have successfully logged in you will an output with some tenant information: LoggedIn

Now for all the available cmdlets let's do a Get-Command -Module MicrosoftTeams:
cmdlets

Anything interesting? Yep: Get-Team, Add-TeamUser and Remove-TeamUser. Easy. Let's get down to it. First let's check if it even works ;):

Get-Team which returns the following:
getteam-1

The next step is to add a user to a Team and here comes a major problem, in the help for Add-TeamUser we can see that we need a GroupID (and yeah I've double and trippled checked):
addteamuser

So we need the GroupID from Get-Team... But... the help file sadly states:
gethelpteam-1

Which means that we can only get the teams available for the user running the command :(. But every problem got a solution, this particular one can be solved by

Get-MsolGroup -SearchString "A Random Name") which uses the MSOnline-cmdlets to retrieve the GroupID. It's not the best but it works:
getmsol

Now for testing the actual commands: Add-TeamUser -GroupId acc689ea-457a-4586-a2d8-2bcb46bae3d5 -User "alexander@arandomname.onmicrosoft.com" -Role Member. It seems to be working:
get-teamuser

But the client takes a bit longer to update, something that Microsoft clearly states in their help-files (up to 1 hour).

To remove a user from a Team we follow the same syntax: Remove-TeamUser -GroupId acc689ea-457a-4586-a2d8-2bcb46bae3d5 -User "alexander@arandomname.onmicrosoft.com".

Next time

In the next post I'll be focusing on making a script (or a function rather) that can synchronize the members of a security group with Teams.

Stay tuned ;)

Andreas Selevik

Andreas Selevik

Solution Architect specialized in Windows & Azure Architecture, Office 365, PowerShell, Identity management and automation. Manchester United fanatic, father, husband and a very good winner...

Read More