SharePoint Online: How to Get All Modern Group Sites using PowerShell?

Requirement: Get Modern Group Team sites in SharePoint Online.

How to Get All Modern Group Sites in SharePoint Online?

Microsoft 365 Group-Connected Modern sites in SharePoint Online offer a modern, responsive design and a wide range of functionalities. This guide will show you how to get all modern sites from the SharePoint admin center and use the SharePoint Online PowerShell module, PnP PowerShell, to connect to your tenant, retrieve all Modern SharePoint Online sites and export the results to a CSV file for further analysis.

In the modern admin center, you can filter sites by their template. Just Login to SharePoint Admin Center >> Expand Sites >> Active Sites >> Mouse over to the template column and filter the template based on your requirement.

sharepoint online get modern team sites using powershell

We can get the list of modern team sites created in a SharePoint Online tenant using the Get-SPOSite cmdlet.

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Variable for Admin Center URL
$AdminSiteUrl = ""

#Connect to SharePoint Online
Connect-SPOService -Url $AdminSiteUrl -Credential (Get-Credential)

#Get All Modern Group Sites
Get-SPOSite -Template GROUP#0 -IncludePersonalSite:$false 

Get Modern Sites using PnP PowerShell

Here is how to use PnP PowerShell to get a list of all group connected sites in your tenant:

#Set variables
$AdminCenterURL = ""

#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Interactive 

#Get All Group Sites
Get-PnPTenantSite -WebTemplate GROUP#0

PowerShell to Export Modern Sites data to CSV File

Let’s get all group-connected sites and export them to a CSV file:

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

$AdminSiteUrl = ""
$CSVPath = "C:\Temp\SiteData.csv"

#Connect to SharePoint Online
Connect-SPOService -Url $AdminSiteUrl -Credential (Get-Credential)

#Get All Modern Group Sites
$GroupSites = Get-SPOSite -Limit All -Template 'GROUP#0' -IncludePersonalSite:$false

#Collect site data
$SiteDataCollection = @()
ForEach($Site in $GroupSites)
    #Add the Data to Object
    $SiteData = New-Object PSObject
    $SiteData | Add-Member NoteProperty Title($Site.Title)
    $SiteData | Add-Member NoteProperty URL($Site.URL)
    $SiteData | Add-Member NoteProperty Size($Site.StorageUsageCurrent)
    $SiteData | Add-Member NoteProperty LastModified($Site.LastContentModifiedDate)
    $SiteDataCollection += $SiteData
$SiteDataCollection | Format-table

#Export Data to CSV File
$SiteDataCollection | Export-Csv -Path $CSVPath -NoTypeInformation

PnP PowerShell to Get All SharePoint Online Sites with Microsoft 365 Groups

This time, from Microsoft 365 groups side, we can retrieve the list of SharePoint Online sites:

#Config Variables
$AdminCenterURL = ""
#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Interactive

#Get All Group Connected Sites
Get-PnPMicrosoft365Group -IncludeSiteUrl | Select DisplayName, Mail, SiteURL, Visibility, GroupId

In summary, By following the steps outlined in this tutorial, you should now be able to use SharePoint Admin center or PowerShell to retrieve a list of all Modern SharePoint Online sites in your tenant. This can be helpful for organization and management, as well as for reporting and analysis.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

2 thoughts on “SharePoint Online: How to Get All Modern Group Sites using PowerShell?

  • This is a lot of help! Is there some way to do the same for Classic sites via Powershell?

    • You mean, get all classic sites? Use:
      Get-SPOSite -Limit All -Template ‘STS#0’ -IncludePersonalSite:$false


Leave a Reply

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