Microsoft 365

Microsoft Teams: List all Teams, Team Members and Team Channels

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 overview 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 of 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

$ErrorActionPreference = "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

List all logged on Users with quser.exe and PowerShell

In this short article I will show how to list all logged on local users with the quser.exe tool. Quser displays information about logged on users on the local computer and on a Remote Desktop Session Host server. PowerShell Code Enter the code below to determine all logged on users. Multiple users, if any, will […]

Monitor Network Connectivity with PowerShell 7 (Successful Pings)

Recently, I have created a script that returns a beep sound when the connection is re-established. I would like to share this script here on my website. Assume your network connectivity is broken. You wait until the connection is restored. In addition, you want to hear a sound when the connection is re-established. For this […]

Exchange: How to export Mailboxes to PST Files

Today I will show you how to export Mailboxes from an Exchange Server to a single PST file. This blog post applies only to On-Premise Exchange Servers. By default, it’s currently not possible to export Mailboxes from Exchange Online. Let’s dive in. Create a Network Share PST files exports can only be stored on a […]

3 replies »

  1. 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?

    Like

  2. 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.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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