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 its template. Just mouse over to the template column and filter 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 Get-SPOSite cmdlet.
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Variable for Admin Center URL
$AdminSiteUrl = "https://crescent-admin.sharepoint.com"

#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
#Set variables
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"

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

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

PowerShell to Export Modern Sites data to CSV File
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Variables
$AdminSiteUrl = "https://crescent-admin.sharepoint.com"
$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
SharePoint Online: How to Get All Modern Group Sites using PowerShell? SharePoint Online: How to Get All Modern Group Sites using PowerShell? Reviewed by Salaudeen Rajack on June 26, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.