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.
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:
Now for all the available cmdlets let's do a
Get-Command -Module MicrosoftTeams:
Anything interesting? Yep:
Remove-TeamUser. Easy. Let's get down to it. First let's check if it even works ;):
Get-Team which returns the following:
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):
So we need the GroupID from
Get-Team... But... the help file sadly states:
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:
Now for testing the actual commands:
Add-TeamUser -GroupId acc689ea-457a-4586-a2d8-2bcb46bae3d5 -User "firstname.lastname@example.org" -Role Member. It seems to be working:
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 "email@example.com".
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 ;)