Microsoft Teams is powered by the SharePoint Online site to store files. When a new team is created in Microsoft Teams, it automatically creates a SharePoint site to store the team’s associated documents. Apart from storing files, the Site will also be used to store the content of the different Team features. For example, the Teams Wiki content will be stored as a hidden SharePoint List in the associated site.
In this blog, we are going to explore how to get all Microsoft Teams and their attached SharePoint site. We can use the Get-UnifiedGroup cmdlet to list all Teams and their SharePoint site URL. Before you start, run the following command to connect Exchange Online module.
Connect-ExchangeOnline
The Get-UnifiedGroup cmdlet returns all the Microsoft 365 Groups, we need to apply a filter with the ResourceProvisioningOptions property to get only teams enabled groups. The below command list all the Teams and their SPO Site URL.
Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"} -ResultSize Unlimited | Select DisplayName, SharePointSiteUrl, ExternalDirectoryObjectId
Export All Teams and Site URL to CSV file
The following commands retrieve all the Microsoft Teams and export the result to a CSV file. The exported report includes the team details such as Team Name, Team Id (Group Id), Team Site URL, Owners, Privacy type, and more.
$Result = @()
#Get all Teams enabled groups
$AllTeamGroups = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"} -ResultSize Unlimited
$AllTeamGroups | ForEach-Object {
$TeamGroup = $_
#Add team detail to $Result array one by one
$Result += New-Object PSObject -property $([ordered]@{
TeamName = $TeamGroup.DisplayName
TeamId= $TeamGroup.ExternalDirectoryObjectId
SharePointSiteUrl = $TeamGroup.SharePointSiteUrl
Owners = ($TeamGroup.ManagedBy -join ", ")
AccessType = $TeamGroup.AccessType
MembersCount = $TeamGroup.GroupMemberCount
ExternalMembersCount = $TeamGroup.GroupExternalMemberCount
CreatedTime = $TeamGroup.WhenCreated
})
}
# Export the result to CSV file
$Result | Export-CSV "C:\AllTeamSiteDetails.CSV" -NoTypeInformation -Encoding UTF8
It can be done far more simply by the command below. BTW, this is completely derivative.
Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"} -ResultSize Unlimited | select DisplayName , ExternalDirectoryObjectId , SharePointSiteUrl , ManagedByDetails , AccessType , GroupMemberCount , GroupExternalMemberCount , WhenCreated|Export-Csv ..\SharePointTeamsSites.csv
Yes, this can be useful who are willing to run a script in one line execution.