In SharePoint Online, you can create two types of sites with the modern experience – Communication sites and Team sites. Each type of site is created with its own set of templates that contain pre-populated content, pages, and web parts that can be customized to fit the needs of your organization. In this article, we will explore how to get Team site, Communication, and OneDrive for Business sites using PnP PowerShell.
Run the following commands to connect PnP PowerShell with your SharePoint Online Admin center site. You need to either have SharePoint Tenant admin or Global admin permission.
#Provide your SharePoint Online Admin center URL
$AdminSiteURL = "https://contoso-admin.sharepoint.com"
#$AdminSiteURL = "https://<Tenant_Name>-admin.sharepoint.com"
#Connect to SharePoint Admin Site
Connect-PnPOnline -Url $AdminSiteURL
The below command retrieves and lists all the available SharePoint sites in the Tenant.
Get-PnPTenantSite
Get all modern Team sites
We can provide value for the parameter Template in the above command to list sites with a specific template. For Microsoft 365 Group associated Team site, the Template Id is GROUP#0. The below command retrieves all the modern Team sites that are connected with Office 365 group.
Get-PnPTenantSite -Template "GROUP#0"
Get all modern Communication sites
For modern Communication sites, the Template Id is SITEPAGEPUBLISHING#0. The below command retrieves all the communication sites.
Get-PnPTenantSite -Template "SITEPAGEPUBLISHING#0"
Get all Team and Communication sites
The parameter Template accepts one template per execution, if you want to retrieve both types of sites in a single command, we need to get all site collections and filter with Template id. The below command gets all modern Team and Communication sites.
Get-PnPTenantSite | Where -Property Template -In ("GROUP#0", "SITEPAGEPUBLISHING#0")
Get OneDrive for Business sites using PnP PowerShell
By default, the Get-PnPTenantSite command does not return OneDrive for Business sites. We need to pass the switch parameter -IncludeOneDriveSites to list OneDrive sites along with other types of sites.
Get-PnPTenantSite -IncludeOneDriveSites
The Template Id for OneDrive for Business site is SPSPERS#10. We can pass this id in the above command to list only the OneDrive user sites.
Get-PnPTenantSite -IncludeOneDriveSites -Template "SPSPERS#10"
We can also use the Filter by Url to search only the personal OneDrive sites.
Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
Just did a query of our tenant and our OneDrive use SPSPERS#9 as the template.
Thanks for reporting. You can Filter by Url (instead of the Template ID) to search only the personal OneDrive sites.
Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"