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

Going Back to an Old Question

Soon after Microsoft launched Teams in 2017, a question appeared in the Microsoft Technical Community to ask how to return a list of 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

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:

$Teams = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"}
$Teams | Sort DisplayName | Select 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 Report

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 Name
If (!($ModulesLoaded -match "ExchangeOnlineManagement")) {Write-Host "Please connect to the Exchange Online Management module and then restart the script"; break}
       
$TeamsList = [System.Collections.Generic.List[Object]]::new()
$Teams = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"}
ForEach ($Team in $Teams) {
  $TeamLine = [PSCustomObject][Ordered]@{
      Team = $Team.DisplayName
      SPOSite = $Team.SharePointSiteURL 
      ManagedBy = $Team.ManagedBy }
  $TeamsList.Add($TeamLine)
}
$TeamsList | Out-GridView
$TeamsList | Export-CSV -NoTypeInformation c:\temp\TeamsSPOList.CSV

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