The PowerShell module for Microsoft Teams lacks functionality compared to the capability of other Office 365 PowerShell modules, however, the latest update, version 0.9.5, provides a working set of commands for basic administration of Teams.

In particular, this update provides a working Get-Team cmdlet that provides a list of all the Microsoft Teams within your tenant. This is really useful if you want to be able to provide reports on your teams, whether for administration purposes, to plan activities like migrations or see some of the detail underpinning your adoption.

Our example script

In the example script below, we’ll use Get-Team to retrieve a list of Teams within the tenant. Whilst Get-Team only returns the Office 365 Group ID, name and description of the Team we can use the Group ID to create a more detailed report about our Teams and the underlying services they utilize. We do this by iterating through each Team, retrieving the membership of the Team using Get-TeamUser, and then retrieving the Unified Group information using Exchange Online PowerShell via Get-UnifiedGroup. Using the more detailed information from that cmdlet, we then use Get-SPOSite to collect information about how much data is stored in the underlying SharePoint Team site, then use Get-MailboxFolderStatistics to understand how many Team Chat messages are journaled back to the Group Mailbox.

Before attempting to use the example script, you’ll need to install both the Teams PowerShell module, and the SharePoint Online Management Shell. The script will connect to both services in addition to connecting to Exchange Online.

param($Credential=(Get-Credential),$CSVFile=".\TeamsReport.CSV")

try {
# Connect Exchange Online PowerShell
$EXOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
$EXOComments = Import-PSSession $EXOSession -DisableNameChecking

#  Get SharePoint URL
$SharePointURL = (Get-OrganizationConfig).SharePointURL
$SharePointAdminURL = $SharePointURL -Replace(".sharepoint.com","-admin.sharepoint.com")

# Connect SharePoint Online
$SPOSession = Connect-SPOService -Credential $Credential -Url $SharePointAdminURL

# Connect Microsoft Teams
$TeamsSession = Connect-MicrosoftTeams -Credential $Credential 
} catch {
    throw $Error
}

# Get All Teams
$Teams = Get-Team

$TeamsOutput = @()

foreach ($Team in $Teams)
{
    $TeamUsers = Get-TeamUser -GroupId $Team.GroupId
    if ([array]$TeamGuest = $TeamUsers | Where {$_.Role -eq "guest"})
    {
        $TeamGuestCount = $TeamGuest.Count
    } else {
        $TeamGuestCount = 0
    }
    
    $UnifiedGroup = Get-UnifiedGroup -Identity $Team.GroupId
    $SPOSite = Get-SPOSite -Identity $UnifiedGroup.SharePointSiteUrl
    $FolderStatistics = Get-MailboxFolderStatistics -Identity $UnifiedGroup.Identity | Where {$_.FolderPath -eq "/Conversation History/Team Chat"}


    $OutputItem = New-Object Object
    $OutputItem | Add-Member TeamDisplayName $Team.DisplayName
    $OutputItem | Add-Member TeamDescription $Team.Description
    $OutputItem | Add-Member TeamAddress $UnifiedGroup.PrimarySmtpAddress
    $OutputItem | Add-Member TeamGuestCount $TeamGuestCount
    $OutputItem | Add-Member HiddenfromOutlook $UnifiedGroup.HiddenFromExchangeClientsEnabled
    $OutputItem | Add-Member StorageUsedMB $SPOSite.StorageUsageCurrent
    $OutputItem | Add-Member TeamChatsinMBX $FolderStatistics.ItemsInFolder

    

    $TeamsOutput+=$OutputItem

}

Remove-PSSession -Session $EXOSession
Disconnect-SPOService
Disconnect-MicrosoftTeams

$TeamsOutput

$TeamsOutput | Select * | Export-Csv -Path $CSVFile -NoTypeInformation

The output of the script produces both console output, and a CSV file both containing columns showing basic Team information, the email address of the Team, the number of Guest users within the Team, if it’s hidden from Outlook, the storage used and the number of Team chats.

In the example output, we provide the credentials used to connect to the services, and the CSV file to create as output:

PS C:\Scripts> $Credential=Get-Credential

PS C:\Scripts> .\Get-TeamsReport.ps1 -Credential $Credential -CSVFile .\TeamsReport.CSV | Format-Table -AutoSize

TeamDisplayName           TeamDescription    TeamAddress                       TeamGuestCount HiddenfromOutlook StorageUsedMB TeamChatsinMBX
---------------           ---------------    -----------                       -------------- ----------------- ------------- --------------
The All About 365 Podcast Podcast            Podcast@allabout365.com           1              False              3201          28
Blog and Twitter          Blog and Twitter   BlogandTwitter@allabout365.com    0              True               1             463
AAC Finances              AAC Finances       AACFinances@allabout365.com       0              True               4             0
Eco Commitee Team         Eco Commitee Team  EcoCommiteeTeam@allabout365.com   0              True               1             3
Admin Team                Admin Team         AdminTeam@allabout365.com         1              True               1             0

PS C:\Scripts> 

Naturally, if you want additional information, you can adjust the script to your needs – examine the output from cmdlets such as Get-UnifiedGroup to understand the additional detail you can retrieve.

Summary

The new Teams PowerShell module provides a more appropriate set of output for Office 365 administrators who need to generate reports about the environment they manage. Whilst it doesn’t provide the depth of other modules, use the updated cmdlets alongside modules like Exchange Online and SharePoint Online to provide the depth of information needed for comprehensive reports.

About the Author

Steve Goodman

Technology Writer and Chief Editor for AV Content at Practical 365, focused on Microsoft 365. A 12-time Microsoft MVP, author of several technology books and regular Microsoft conference speaker. Steve works at Advania in the UK as Field Chief Technology Officer, advising business and IT on the best way to get the most from Microsoft Cloud technology.

Comments

  1. Anthony Mootra

    Hi All,
    I would like to filter the Teams accounts by Department as my organization has about 8000 * users but need to show activity by department. Is there an easy way to do this?

  2. Chris Muller

    Trying to execute this from my new laptop. What do I need to install to use Get-OrganizationConfig? Thanks.

  3. sankar

    how we can find who created this team site and what date

  4. Nati

    Perfect!
    I never understood why an admin gets to see only the teams is member of with Get-Teams.
    Luckily we also got Graph that is doing amazing job

  5. James

    It’s a nice script but Get-Team doesn’t return all teams within a tenant but rather returns a list of teams that the user (running the cmdlet) is a member of. They really need to update the cmdlet to allow it to return all teams regardless.

    1. Tuomas Pakkanen

      Latest version of the Teams PowerShell module does in fact return all Teams.

    2. Steve Goodman

      As Tuomas says, it’s been updated – hence the purpose of the post and this script ?

      Steve

      1. Guy

        Have you experienced any differences in the amount of Teams returned through Get-Team vs Get-UnifiedGroup where you filter Teams Only groups?
        The reason I’m asking is since I’ve been using the latest version in two different tenants, and though it seems to return all the Teams in a tenant, I noticed that there are few Teams that are not being returned (seems as the ones that were created through the Teams client itself), but they are returned if I use Get-Team -User [username] against a user that is member of those teams.

Leave a Reply