Everyone is talking about Microsoft Teams at this time. Me too. So I decided to focus more and more on this cloud technology, in particular the automation of it. In this blog post I will show you how you can get a list of all your teams, team members and team channels of your tenant at once to get a perfect overview of your environment. Let’s slip into it.
The Objective
We want to see this screen. A nice overwiew of all teams, team users and team channels.

The Code
Copy the code below into PowerShell ISE or Visual Studio Code and run it. The code will detect whether the MSTeams Module is installed. If it is not installed, the script will install the right module for you.
<#
.SYNOPSIS
Lists all Microsoft Teams by name, team members and team channels.
.DESCRIPTION
Copy this code into an editor or your choosing
(recommended: PowerShell ISE or VS Code)
.NOTES
Author: Patrick Gruenauer | Microsoft MVP PowerShell
Web: https://sid-500.com
#>
# Check if Teams Module is installed. If not, it will be installed
If (-not (Get-Module -ListAvailable | Where-Object Name -eq 'MicrosoftTeams' ))
{
Install-Module -Name MicrosoftTeams -Force -AllowClobber
}
# Connect to Microsoft Teams
Connect-MicrosoftTeams
# List all Teams and all Channels
$ErrorAction = "SilentlyContinue"
$allteams = Get-Team
$object = @()
foreach ($t in $allteams) {
$members = Get-TeamUser -GroupId $t.GroupId
$owner = Get-TeamUser -GroupId $t.GroupId -Role Owner
$channels = Get-TeamChannel -GroupId $t.GroupId
$object += New-Object -TypeName PSObject -Property ([ordered]@{
'Team'= $t.DisplayName
'GroupId' = $t.GroupId
'Owner' = $owner.User
'Members' = $members.user -join "`r`n"
'Channels' = $channels.displayname -join "`r`n"
})
}
Write-Output $object
That’s it for today. Thank you for reading this article.
See also

Test-Environment: Building an Active Directory OU structure with Groups and Users with PowerShell Automation
You have just started learning something new and you are now about to bulid up a test environment with Windows Server ? For a good test environment, you will need a Domain-Controller and some OUs, Groups and users to play with. In this blog post I will provide a script for download that enables you […]

PowerShell: Install Software via Online Repository (Chocolatey)
Chocolatey is an Online Respository for popular software products. Online repositories provide a convenient way to install software, such as Adobe Reader, WinZip … It is also possible to install multiple software at once. In this blog post I will carry out installing chocolatey and perfrom some action with it. Let’s dive in. Install Chocolatey […]
Nächster Abendkurs (31.05.2021 – 23.06.2021 18:00 – 21:30) : Einführung in PowerShell via MS Teams (DE)
Liebe Follower! Der nächste PowerShell Kurs findet vom 31.05.2021 bis 23.06.2021 jeweils abends montags und mittwochs statt. Mehr Informationen finden Sie hier: PowerShell Training – Patrick Grünauer (sid-500.at) Ich freue mich auf zahlreiche Teilnahme und spannende Abende. Liebe Grüße, Patrick Grünauer
Categories: Microsoft 365, PowerShell
great thanks
just in this part
$object += New-Object -TypeName PSObject -Property ([ordered]@{
i know you managed the “ordered” method
but i obtainied great result without the need of order with this instead.
$object+=[pscustomobject]@{
also another question, if you export to CSV with that format you have is working? have you tried?
LikeLike
Thank you for your feedback. Csv export should be fine.
LikeLike
Learning a great deal from your blogs. Being a newbie using powershell I always tend to look forward to new posts.
I’m struggling with enabling users to Teams enterprise voice and adding them one by one a Number etc. using the SetCSOnline, GrantCSOnline voice routing policy.
LikeLiked by 1 person