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?

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

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply