Microsoft Teams – PowerShell, a complete getting started guide.

With the release of PowerShell for Microsoft Teams  a massive step has been taken towards an easier to manage application. I like Microsoft  Teams and PowerShell, so what more could I wish for with PowerShell for Microsoft Teams.

In this post I’m going through the commands and this pains that I have found on my way. It’s only a new product so I would expect to find some issues.

Microsoft Teams all starts by installing the module. It’s made very easy as all you have to do is run the following in an administrator version of PowerShell

[code lang=text]
Install-Module MicrosoftTeams

Once the module as been installed, we can get started with our discoveries.

It help to restart your PowerShell ISE after installing the module as the module will then get properly loaded.Microsoft Teams - PowerShell, a complete getting started guide. 1

To get started it always helps to run Get-TeamHelp first as this will give you an overview of the available commands.

This will show all of the 23 commands available.

  • Get-TeamHelp
  • Connect-MicrosoftTeams
  • Disconnect-MicrosoftTeams
  • Get-Team
  • Get-TeamUser
  • Get-TeamChannel
  • Get-TeamMemberSettings
  • Get-TeamMessagingSettings
  • Get-TeamFunSettings
  • Get-TeamGuestSettings
  • New-Team
  • New-TeamChannel
  • Add-TeamUser
  • Remove-Team
  • Remove-TeamChannel
  • Remove-TeamUser
  • Set-TeamMemberSettings
  • Set-TeamMessagingSettings
  • Set-TeamFunSettings
  • Set-TeamGuestSettings
  • Set-TeamPicture
  • Set-Team
  • Set-TeamChannel

Note that this PowerShell for Microsoft Teams is still in Beta as shown when you use Get-Help

[code lang=text]
Get-Help Get-TeamHelp

Microsoft Teams - PowerShell, a complete getting started guide. 2

Connecting to MicrosoftTeams

All of the Microsoft teams commands start by making a connection to your tenant.

There are multiple ways that you can use Connect-MicrosoftTeams.

A simple call the Connect-MicrosoftTeams will already work:

[code lang=text]

You will get a login dialog and a connection will be set up.

When you automate things you might want to use the -Credential parameter. So that you can reuse credentials once entered.

One important note to make is that when you connect using Connect-MicrosoftTeams a connection object is returned with details like tenantId.
Microsoft Teams - PowerShell, a complete getting started guide. 3

Disconnecting to MicrosoftTeams

There is a command available to disconnect, however I haven’t evr found a real need to do this as connecting to a different tenant can simply be done without disconnecting. I guess the disconnect will clean the connection up a bit better.

[code lang=text]

Get your teams

This command gets all the teams that a user belongs to. See my earlier posts get All your teams using PowerShell/

Note that you can only get your own teams. So far I found that even administrators can’t get an overview of a specific user that isn’t the administrator themselves. The Parameter -User therefore seems to be a bit useless.

Users management within a team

The command Get-TeamUser can give you all the users within a team. Using the -GroupId parameter you can select the team (or actually group) that you are interested in. The GroupId you can get my running a Get-Team first.

Microsoft Teams - PowerShell, a complete getting started guide. 4

Additionally if you want to filter the users returned by their role then you could use the -Role parameter

[code lang=text]
Get-TeamUser -GroupId b7d0dfa6-9935-4587-871b-e942d99eae83 -Role guest

This will give you all the guest users within a specified group. in a similar way you cold get all the owners or members of a team.

If you want to add any users to a team then Add-TeamUser will give you what you need. Imagine that you cold now add a user to 100 teams in a matter of seconds.

And of course there is also a Cmdlet available to reove a user form you teams, Remove-TeamUser will do a jobs very nicely

Getting all channels within a team

I didn’t manage to get this to work.

Microsoft Teams - PowerShell, a complete getting started guide. 5

The following error doesn’t seem to want to go away in any kind:

Get-TeamChannel : Error occurred while executing
Code: BadRequest
Message: Resource not found for the segment ‘channels’.
RequestId: b913cd5f-8809-4b13-8650-844e8b261294
DateTimeStamp: 2017-11-06T10:07:02
HttpStatusCode: BadRequest
At line:1 char:2
+ Get-TeamChannel -GroupId b7d0dfa6-9935-4587-871b-e942d99eae83
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TeamChannel], ApiException
+ FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custom.GetTeamChannel

Team Member Settings

There are 2 CmdLets for team member settings:

Get-TeamMemberSettings  and Set-TeamMemberSettings

The Get Cmdlet will return the current values of the settings

AllowCreateUpdateChannels : True
AllowDeleteChannels : True
AllowAddRemoveApps : True
AllowCreateUpdateRemoveTabs : True
AllowCreateUpdateRemoveConnectors : True

The Set CmdLet has Parameters for each of the settings so that you can change the settings

Team Messaging Settings

For Team Messaging settings we have again a Set and  Get Cmdlet available.

Microsoft Teams - PowerShell, a complete getting started guide. 6

The Set Cmdlet will make it possible to set the following 5 parameters:

  • AllowUserEditMessages
  • AllowUserDeleteMessages
  • AllowOwnerDeleteMessages
  • AllowTeamMentions
  • AllowChannelMentions

Guest Settings

Get-TeamGuestSettings and Set-TeamGuestSettings handle two of the settings available within Microsoft teams.

  • AllowCreateUpdateChannels
  • AllowDeleteChannels

So this again matches the settings already available within the app.

Fun Settings

Get-TeamFunSettings and Set-TeamFunSettings handle four of the settings available within Microsoft teams.

  • AllowGiphy
  • GiphyContentRating
  • AllowStickersAndMemes
  • AllowCustomMemes

So this again matches the settings already available within the app and now available from the PowerShell Command line.

Team and Channel Creating

So now we have 4 Cmdlets left:

  • New-Team
  • New-TeamChannel
  • Remove-Team
  • Remove-TeamChannel

We’ll start by creating a new team.

[code lang=text]
New-Team -DisplayName “PowerShell Team” -Description “This was created by PowerShell” -AccessType Private -AddCreatorAsMember $true

There are two more options available Alias and Classification, however I’ve not found that these options do very much for now.


So some of the basic operations and settings are now available. This is by no means a complete set of PowerShell Cmdlets, so expect that there will be more Cmdlets to become available over time …

One thought on “Microsoft Teams – PowerShell, a complete getting started guide.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: