How to Get All SharePoint Site Collections Using PowerShell?

In this tutorial, I will explain how to get all SharePoint site collections using PowerShell with various examples.

How to Get All SharePoint Site Collections Using PowerShell

We can get all SharePoint site collections using two different approaches. Such as:

  1. Get all the SharePoint site collections using SharePoint Online Management PowerShell.
  2. Get all the SharePoint site collections using Pnp PowerShell.

We can use the Windows PowerShell ISE or Visual Studio Code to execute the PowerShell command.

Get all SharePoint Site Collections Using SharePoint Online Management Shell

In PowerShell, the Get-SPOSite cmdlet retrieves all the SharePoint site collections from the Active sites in the SharePoint admin center.

Syntax:

Get-SPOSite
[-Identity] <SpoSitePipeBind>
[-Detailed]
[-Limit <String>]
[-Filter <String>]
[-IncludePersonalSite <Boolean>]
[-Template <String>]
[-GroupIdDefined]
[-ArchiveStatus <String>]
[-DisableSharingForNonOwnersStatus]

Where,

  • Identity: It specifies the URL of the site collection.
  • Detailed: It specifies the detailed information for all site collections.
  • Limit: This specifies the maximum number of site collections. By default, it returns the 200 site collections. To retrieve all site collections, use ALL.
  • Filter: This specifies the filter that is applied to a site collection. Valid operators are —eq,—ne,—like, —notlike.
  • IncludePersonalSite: It displays the personal sites when the value is $true.
  • Template: This specifies the type of site template, such as STS#0 (Team site (classic experience)), STS#3 (Team site (no Microsoft 365 group)), SITEPAGEPUBLISHING#0 (Communication site), and GROUP#0 (Team site (Microsoft 365 group)).
  • GroupIdDefined: This specifies the sites connected to a Microsoft 365 group when the value is $true.
  • ArchiveStatus: It displays sites of a specific archive status. For example, Archived, NotArchived, RecentlyArchived, FullyArchived, and Reactivating.
  • DisableSharingForNonOwnersStatus: This specifies the sites prevent non-owners from sharing.

Example-1:

This PowerShell command will give all the SharePoint sites from the Active sites in the SharePoint admin center.

Get-SPOSite
  • Execute the above command by clicking the Run button, and all the SharePoint site collections will appear in the console.
get all SharePoint site collections using PowerShell

The console shows a list of all SharePoint site collections, including their URLs, owners, and storage quotas.

Example-2:

This command gives detailed information for the SharePoint site collections.

Get-SPOSite -Detailed
  • Click on the Run button. In the console a warning message will appear: “The Detailed parameter will be deprecated for bulk enumeration.” and display the output.
get all SharePoint site collections PowerShell

Example-3:

This example gives details for the specific SharePoint site url.

Get-SPOSite -Identity https://szg52.sharepoint.com/sites/PythonTraining -Detailed 
  • Click the Run button to show specific URL details of the SharePoint site in the console.
get a list of all SharePoint sites PowerShell

Example-4:

This example filters the SharePoint site collections using the template. It only gives the Team site (STS#3 (no Microsoft 365 group)).

Get-SPOSite -Filter { Template -eq "STS#3" } | ft Url,Template,Owner  
  • Click the Run button to filter the SharePoint site collections and show the Url, Template, and Owner in the console.
get all list of SharePoint sites using PnP PowerShell

Example-5:

This PowerShell command to give limited SharePoint site collections is not connected to a Microsoft 365 group.

Get-SPOSite -Limit "20" -GroupIdDefined $false
  • Click the Run button. A warning message will appear in the console: More results were found but were not returned. Use ‘-limit ALL’ to return all possible results. It shows a specific set of SharePoint site collections that are not connected to Microsoft 365 groups.
get all SharePoint site collection PowerShell

If you want to display all the SharePoint site collections, set the Limit parameter value to ALL.

Example-6:

This example displays sites of a specific archive status.

Get-SPOSite -ArchiveStatus "Archived"
  • Click on the Run button to show only the Archived SharePoint site collection in the console.
get all site collections in SharePoint online PowerShell

This is how to get all the SharePoint site collections using SharePoint Management PowerShell.

Get all SharePoint Site Collections Using PnP PowerShell

In this section, I will show you how to get all the SharePoint site collections using PnP PowerShell.

This Get-PnPTenantSite cmdlet retrieves all the SharePoint site collections from the Active sites in the SharePoint admin center.

Syntax:

Get-PnPTenantSite
[-Identity <String>]
[-Detailed]
[-Template  <String>]
[-IncludeOneDriveSites]
[-GroupIdDefined <Boolean>]
[-Filter  <String>]
[-DisableSharingForNonOwnersStatus]

Where,

  • IncludeOneDriveSites: It retrieves all site collections, including all OneDrive sites.

Example-1:

This PnP PowerShell command will give all the SharePoint site collections from the active sites in the SharePoint admin center.

Get-PnPTenantSite
  • Click on the Run button to show all the SharePoint site collections along with the Url, Template, and LocaleId in the Terminal.
how to get SharePoint site collections using PnP PowerShell

Example-2:

This example gives the specific SharePoint site Url information.

Get-PnPTenantSite -Identity "https://szg52.sharepoint.com/sites/EventPlanning"
  • Click on the Run button to show the specific SharePoint site Url along with the Url, Template, and LocaleId in the Terminal.
how to get all site collections in SharePoint online PowerShell

Example-3:

This PowerShell command filters the SharePoint site collections based on their Url.

Get-PnPTenantSite -Filter "url -like 'Project' "
  • Click the Run button to display all site collections with “Project” in their URLs.
how to get all SharePoint sites PowerShell

Example-4:

This PowerShell command gives all the SharePoint site collections, including all OneDrive sites.

Get-PnPTenantSite -IncludeOneDriveSites
  • Click the Run button to show all the OneDrive and SharePoint site collections in the Terminal.
get a list of all SharePoint site collections using  PowerShell

Example-5:

This command gives SharePoint sites that are connected to a Microsoft 365 group.

Get-PnPTenantSite -GroupIdDefined $true
  • Click on the Run button to show which SharePoint sites are connected to the Microsoft 365 group in the Terminal.
get all list of SharePoint site collection using  pnp PowerShell

This is how to get all the SharePoint site collections using PnP PowerShell.

I provided various examples in this article and showed you how to get all the SharePoint Online site collections using SharePoint Management PowerShell and PnP PowerShell.

I hope you found this tutorial helpful!

Also, you may like some more PowerShell articles: