How to find SharePoint sites that are connected with Microsoft Teams

The easier method to find what SharePoint sites relate to Microsoft Teams

I have implemented the easier method to find what SharePoint sites relate to Microsoft Teams.
The following situations include a connection between Teams and SharePoint:
• Upon creating a new team, a new SharePoint site is set up and linked to the group.
• The team is linked to the SharePoint site that is attached to the group when it is formed from an already-existing Microsoft 365 group.
• An already-existing SharePoint site becomes linked to the newly created team when you add Teams to it.
• A new SharePoint site is generated and linked to a newly formed private or shared channel.
Within Teams, every standard channel’s Files tab is linked to a folder located in the parent site’s default document library. All private and shared channels have a Files tab that links to the channel site’s default document library. The SharePoint site is accessed each time you add or modify a file on the Files tab.

This script retrieves details about SharePoint sites that are connected to Microsoft Teams and exports the information to a CSV file, for our demonstration I have created a folder temp in C: be sure to create a folder and make the appropriate change to the script.
Before running the commands, make sure you have installed the Exchange Online PowerShell V3 module and the SharePoint Online PowerShell module.
Connect to Exchange Online and SharePoint Online using the following commands:

Connect-SPOService -Url “https://YourTenantName-admin.sharepoint.com”
Connect-ExchangeOnline

$Result = @()
$AllSites = Get-SPOSite -IncludePersonalSite:$False -Limit All | Select Title, URL
$TotalSites = $AllSites.Count
$i = 1

ForEach ($Site in $AllSites) {
Write-Progress -Activity “Processing $($Site.Title)” -Status “$i out of $TotalSites completed”
$O365Group = $null
$TeamEnabled = $false

# Get the GroupId property for each site
$GroupId = (Get-SPOSite $Site.URL -Detailed).GroupId.Guid

if ($GroupId -ne $null) {
    $O365Group = (Get-UnifiedGroup -Identity $GroupId -ErrorAction SilentlyContinue)
    if ($O365Group -ne $null -and $O365Group.resourceProvisioningOptions -contains "Team") {
        $TeamEnabled = $true
    }
}

$Result += New-Object PSObject -property @{
    SiteName = $Site.Title
    SiteURL = $Site.URL
    GroupEnabled = if ($O365Group -ne $null) { $true } else { $false }
    GroupName = if ($O365Group -ne $null) { $O365Group.DisplayName } else { $null }
    GroupID = if ($O365Group -ne $null) { $GroupId } else { $null }
    GroupMail = if ($O365Group -ne $null) { $O365Group.PrimarySmtpAddress } else { $null }
    GroupOwner = if ($O365Group -ne $null) { $O365Group.ManagedBy -Join "," } else { $null }
    TeamEnabled = $TeamEnabled
}
$i++

}

$Result | Select SiteName, SiteURL, GroupEnabled, GroupName, GroupID, GroupMail, GroupOwner, TeamEnabled | Export-CSV “C:TEMPAllSPOSites.CSV” -NoTypeInformation -Encoding UTF8

Also, you may find the ps script on my GitHub page: https://github.com/Nikolaidis-CloudStories/SharepointOnline/blob/main/Find%20Teams%20connected%20to%20spsites.ps1

The code will return the following info:

SiteName, SiteURL, GroupEnabled, GroupName, GroupID, GroupMail, GroupOwner, TeamEnabled

At the end of the script, the file is exported

More info:

u003ca href=u0022https://learn.microsoft.com/en-us/sharepoint/teams-connected-sitesu0022u003eTeams and SharePoint integration – SharePoint in Microsoft 365 | Microsoft Learnu003c/au003e: The easier method to find what SharePoint sites relate to Microsoft Teams

Leave a Reply

Your email address will not be published. Required fields are marked *