Tom Talks Microsoft Teams and Microsoft 365 news and opinions

Microsoft Teams PowerShell: Getting All Teams, Changing Team Settings and Adding and Removing Users from Teams

As of Microsoft Teams PowerShell 0.95, you can now get and administer all Microsoft Teams as an Office 365 administrator. Previous to 0.95 release, it only worked for teams the current user running the PowerShell was a member of, which made it too limited for any real administration.

First, run PowerShell as a local administrator and install the Module

Install-Module -Name MicrosoftTeams -Repository PSGallery

image

If you get a warning about an old version, you can first uninstall the old version with Uninstall-Module MicrosoftTeams

image

Then connect, you will get prompted for credentials

Connect-MicrosoftTeams

image

Cmdlets available:

image

Get-Team now gets all Teams in your org, not just the ones you are a member of:

image

Get Team Members and Owners (note it uses GroupId not DisplayName:

image

Add a Member to a Team. Can be either a Public or Private Team

image

image

Remove Member from a Team

image

Remove-TeamUser doesn’t seem to put a message into the general channel

image

But the member is removed:

image

There are no confirmation of successful actions, but you will get errors if references or syntax are wrong:

image

Simple script to add a user to all Teams (we use this for reporting)

# Install the Microsoft Teams PowerShell Module from PSGallery
# Default install Path C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams
Install-Module -Name MicrosoftTeams -Repository PSGallery

# Connect to Microsoft Teams
Connect-MicrosoftTeams

# Script to Get all Teams and Add an account as a memeber

$UserToAdd = “TWA.Reporting@domain.com”

$AllTeams = Get-Team

Foreach ($Team in $AllTeams)
{
Write-Host “Adding to $($Team.DisplayName)”
Add-TeamUser -GroupId $Team.GroupID -User $UserToAdd -Role Member
#Sleep Pause so as not to hit the API to hard
Start-Sleep -Seconds 2
}

You can also create new teams and channels, and get and change settings for Teams:

image

image

image

image

image

Reference

Module: https://www.powershellgallery.com/packages/MicrosoftTeams/0.9.5

Teams Help: https://docs.microsoft.com/en-us/powershell/module/teams/?view=teams-ps

About the author

Tom Arbuthnot

A Microsoft MVP and Microsoft Certified Master, Tom Arbuthnot is Founder and Principal at Empowering.Cloud as well as a Solutions Director at Pure IP.

Tom stays up to date with industry developments and shares news and his opinions on his Tomtalks.blog, UC Today Microsoft Teams Podcast and email list. He is a regular speaker at events around the world.

Add comment

Leave a Reply

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

Tom Talks Microsoft Teams and Microsoft 365 news and opinions