How to Generate a Report of Teams and Their SharePoint Online Sites

Going Back to an Old Question

Updated 14 September 2023

Soon after Microsoft launched Teams in 2017, a question appeared in the Microsoft Technical Community to ask how to report Teams and their associated SharePoint Online sites.

Several years later, a response appeared in the thread advocating the technique of fetching the set of Teams in the tenant using these steps:

  • Run Get-Team to get the list of Teams.
  • Run Get-SPOSite to get the list of sites.
  • Loop through the teams to find the site for each team in the list of sites.

One particular joy of PowerShell is that there’s usually several answers to a question. Allied to the number of PowerShell modules available within Office 365, you end up with multiple approaches to explore to find the best answer to a relatively simple question.

Another complication is that Microsoft updates cmdlets over time, usually to good effect. They also update objects in the background to add new properties, remove old properties, and improve how things work, often to support the introduction of new features.

A Better Answer for a Teams Report

Which brings me to my two-line answer to the question. Use the Get-UnifiedGroup cmdlet to return the set of team-enabled groups and then list the set of teams and their SharePoint Online sites. Apart from anything else, this uses one module (Exchange Online Management) instead of two. The code is:

[array]$Teams = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"}
$Teams | Sort-Object DisplayName | Select-Object DisplayName, SharePointSiteUrl | Export-CSV -NoTypeInformation "C:\Temp\TeamsSPOList.CSV"

To be fair to the folks who responded in the thread going back to 2017, this answer wasn’t possible then. Microsoft 365 Groups had an odd provisioning flag that was never reliable and the Get-UnifiedGroup cmdlet didn’t support filtering for teams. Even in the answer cited above, a group’s ResourceProvisioningOptions property, which first appeared a couple of years ago and should have the value “Team” for team-enabled groups, wasn’t always populated. That problem appears to have gone away. At least, in my tenant, the count of objects and the actual objects returned by Get-Team and Get-UnifiedGroup (with the filter) are identical.

Having support for a filter is also important because it means that the server (Exchange Online) does the work to find team-enabled groups and only returns those objects. This is much faster than finding all Microsoft 365 Groups and then filtering them on the workstation to figure out which are team-enabled.

Creating a Teams Report with SharePoint URLs

A two-line answer does the job, but a more complete answer is to create a nice report. Here’s a simple script to do just that:

# Check that we are connected to Exchange Online
$ModulesLoaded = Get-Module | Select-Object -ExpandProperty Name
If (!($ModulesLoaded -match "ExchangeOnlineManagement")) {Write-Host "Please connect to the Exchange Online Management module and then restart the script"; break}
       
Write-Host "Finding Teams..."
[array]$Teams = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"}
If (!($Teams)) {
   Write-Host "Can't find any Teams for some reason..."
} Else {
  Write-Host ("Processing {0} Teams..." -f $Teams.count)
  $TeamsList = [System.Collections.Generic.List[Object]]::new()    
  ForEach ($Team in $Teams) {
   $ManagedBy = $Team.ManagedBy; [string]$MemberDisplayName = $Null; [array]$DisplayNames = $Null
   ForEach ($Member in $ManagedBy) {
      $MemberDisplayName = (Get-ExoRecipient -Identity $Member -RecipientTypeDetails UserMailbox).DisplayName
      $DisplayNames += $MemberDisplayName
   }
   $TeamLine = [PSCustomObject][Ordered]@{
      Team = $Team.DisplayName
      SPOSite = $Team.SharePointSiteURL 
      ManagedBy = $DisplayNames -join ", " }
   $TeamsList.Add($TeamLine)
  }
$TeamsList | Out-GridView
$TeamsList | Export-CSV -NoTypeInformation c:\temp\TeamsSPOList.CSV
}

Report Teams Output

The report output is to the screen using Out-GridView (Figure 1) and a CSV file. But as it’s PowerShell, you can change the code to do whatever you want.

Reporting Microsoft Teams and their SharePoint Online sites

Teams report
Figure 1: Reporting Microsoft Teams and their SharePoint Online sites

Apart from anything else, this exercise proves that if you write PowerShell scripts to manage an Office 365 tenant, you need to keep an eye on changes introduced in updated modules.


The Office 365 for IT Pros eBook has a complete chapter on using PowerShell to create innovative solutions to system administration issues. Subscribe now and benefit from monthly updates.

2 Replies to “How to Generate a Report of Teams and Their SharePoint Online Sites”

Leave a Reply

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