How to get modern Team & Communication sites using PnP Powershell

This post list out the powershell command from PnP used to retrieve the modern SharePoint sites from the tenant

PnP Powershell commands are one of the powerful player in accessing and managing the SharePoint Online / On-Premise sites from remote machine. PnP team keep on updating the commands based on the updating feature released on SharePoint Online & On-premise tenants.

For now a days, we are keep on talking about modern  team and communication sites. Here I’m going to list out the commands to get the details on the modern sites created based on the team and communication templates.

Visit SharePoint/PnPPowerShell from Github to know more about PnP Powershell and you can view all the powershell cmdlets from PnPPowershell Documentation

In this post, I’m giving you an example based on SharePoint online. So I have installed the online module called “SharePointPnPPowerShellOnline”.

Before accessing the SharePoint objects, open the powershell command prompt and ensure latest powershell module installed on your machine. Use the below command to update to the latest SharePointPnPPowerShellOnline module,

PS:> Update-Module SharePointPnPPowerShell*

Use the below command references to connect the SharePoint online site
PS:> $credential = Get-credential
PS:> Connect-PnPOnline -Url https://ktskumar.sharepoint.com -Credential $credential

Once we got connected to the SharePoint site, use the below commands to get the list of available sites in SharePoint tenant.

Get all SharePoint sites except Modern sites

PS:> Get-PnPTenantSite

The above PnP powershell command retrieves and  shows the available SharePoint classic sites in the Tenant. It doesn’t returns the sites created with modern templates. We may expect this command to show classic and modern sites in coming days.

Get all SharePoint sites including modern and onedrive sites

PS:> Get-PnPTenantSite - IncludeOneDriveSites

The above PnP command retrieves and shows the classic, modern and OneDrive for Buisness sites from the Tenant.

Get all Modern Team SharePoint sites

PS:> Get-PnPTenantSite -WebTemplate GROUP#0

The above PnP powershell command gets and lists the sites created based on Modern team site template from the SharePoint tenant. And each site is associated with a Office 365 group.

Get all Modern Communication SharePoint sites

PS:> Get-PnPTenantSite -WebTemplate SITEPAGEPUBLISHING#0

The above PnP powershell command lists the communication sites from the SharePoint tenant.


The SharePoint online site collection information are stored in the hidden list called “DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS” under SharePoint Tenant Administration site and this list has the below columns

AllowGuestUserSignIn PrimaryAdmin SMTotalSize
Classification ShareByEmailEnabled StorageQuota
ExternalSharing ShareByLinkEnabled StorageQuota.
FileViewedOrEdited SiteId StorageUsed
IsGroupConnected SiteOwnerEmail StorageUsed.
LastActivityOn SiteOwnerName TemplateTitle
LastActivityOn.FriendlyDisplay SiteSecondaryOwnerEmail TimeCreated
NumOfFiles SiteSecondaryOwnerName TimeDeleted
PageViews SiteUrl Title

List URL: https://<tenant>-admin.sharepoint.com/Lists/DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECO

By using the this list, we can also categorize and retrieve the modern site collections. Use the below command references to connect the SharePoint Tenant Administration online site
PS:> $credential = Get-credential
PS:> Connect-PnPOnline -Url https://ktskumar-admin.sharepoint.com -Credential $credential

Get all site collections from Tenant – from List

PS:> Get-PnPListItem -List DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS -Fields ID,Title,TemplateTitle,SiteUrl,IsGroupConnected

The above powershell command prompt returns you the ID, Title, TemplateTitle, SiteUrl and ISGroupConnected information about the SiteCollections.

All Site Collections
All Site Collections

Get all Modern Team SharePoint Sites – from List

PS:> Get-PnPListItem -List DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS -Query "<View><Query><Where><Eq><FieldRef Name='TemplateTitle'/><Value Type='Text'>Team Site</Value></Eq></Where></Query><ViewFields><FieldRef Name='Title'/><FieldRef Name='ID'/><FieldRef Name='TemplateTitle'/></ViewFields></View>"

To get the modern team sites alone, We should write the query to filter the modern team site information based on the TemplateTitle column as Team Site.

Modern Team Site Collections
Modern Team Site Collections

Get all Modern Communication SharePoint Sites – from List

PS:> Get-PnPListItem -List DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS -Query "<View><Query><Where><Eq><FieldRef Name='TemplateTitle'/><Value Type='Text'>Communication Site</Value></Eq></Where></Query><ViewFields><FieldRef Name='Title'/><FieldRef Name='ID'/><FieldRef Name='TemplateTitle'/></ViewFields></View>"

To retrieve the modern communication (showcase, topic, blank) SharePoint site collections from tenant, we have to filter the list based on TemplateTitle as Communication Site

Modern Communication Site Collections
Modern Communication Site Collections

Get Office 365 group connected SharePoint Sites – from List

PS:> Get-PnPListItem -List DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS -Query "<View><Query><Where><Eq><FieldRef Name='IsGroupConnected'/><Value Type='boolean'>1</Value></Eq></Where></Query></View>"

To retrieve the Office 365 group team site, use the IsGroupConnected column from the list. This returns the SiteCollections, which are created with Office 365 group or connected with existing Office 365 group.

Office365 Group Site Collections
Office365 Group Site Collections

We can use this List to fetch the various Site Collection information based on the available columns.

Summary:

Modern SharePoint Admin center and updated PnP Powershell commands helps to retrieve most of the Site Collection information and we can expect more options for managing the SharePoint tenant.

Shantha Kumar
Shantha Kumar
Articles: 278

24,849 Comments

Comments are closed.