How to Get All SharePoint Site Collections Using PowerShell?

If you manage SharePoint Online, sooner or later someone will ask: “Can you send me a list of all SharePoint sites in our tenant?” It sounds simple, but doing this manually from the admin center is slow, error‑prone, and painful when you have hundreds of sites. This is where you can use PowerShell to get a complete, repeatable inventory of all site collections in just a few commands.

In this tutorial, let’s walk through how to get all SharePoint site collections from your tenant using both the SharePoint Online Management Shell and PnP PowerShell, and also see how to filter and export this data to CSV for reporting.

Prerequisites

Before you start, make sure you have a few basics in place.

  • You need to be a SharePoint admin (or Global admin) in the tenant.
  • Install the SharePoint Online Management Shell module on your machine.
  • Install PnP PowerShell (cross‑platform, recommended for modern automation).
  • Know your SharePoint Admin Center URL, e.g. https://yourtenant-admin.sharepoint.com.

You can install the modules from an elevated PowerShell window:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Install-Module -Name PnP.PowerShell

Once the prerequisites are installed, you can connect to SharePoint Online.

Connect to SharePoint Online

To work with SharePoint Online, you must first connect to your tenant.

Using SharePoint Online Management Shell

$AdminUrl = "https://yourtenant-admin.sharepoint.com"
Connect-SPOService -Url $AdminUrl

This will prompt you to sign in with your SharePoint admin account.

Using PnP PowerShell

$AdminUrl = "https://yourtenant-admin.sharepoint.com"
Connect-PnPOnline -Url $AdminUrl -Interactive

The -Interactive switch gives you the standard Microsoft sign‑in prompt with MFA support.

Check out Create a SharePoint Online Site Using PowerShell

Get All SharePoint Site Collections with Get‑SPOSite

The Get‑SPOSite cmdlet comes from the SharePoint Online Management Shell module and is designed to work at the tenant level.

Basic syntax

Get-SPOSite [-Identity] [-Detailed] [-Limit] [-Filter] [-IncludePersonalSite] [-Template] `
            [-GroupIdDefined] [-ArchiveStatus] [-DisableSharingForNonOwnersStatus]

A few important parameters:

  • Identity – URL of a specific site collection.
  • Detailed – Returns more properties for each SharePoint site collection.
  • Limit – Number of sites to return; use -Limit All to retrieve everything.
  • Filter – Server‑side filter with operators like -eq-ne-like-notlike.
  • IncludePersonalSite – Include personal OneDrive sites when set to $true.
  • Template – Filter by site template (e.g., STS#0STS#3SITEPAGEPUBLISHING#0GROUP#0).
  • GroupIdDefined – $true for sites connected to Microsoft 365 groups.
  • ArchiveStatus – Filter by archive state (Archived, NotArchived, etc.).
  • DisableSharingForNonOwnersStatus – Shows sites where non‑owners cannot share.

Example 1: List all SharePoint Site Collections

By default, Get-SPOSite returns only 200 sites in SharePoint, so you should always set -Limit All for a full inventory.

Connect-SPOService -Url "https://yourtenant-admin.sharepoint.com"

# Get all site collections
Get-SPOSite -Limit All

This shows you each SharePoint site’s URL, owner, storage details, and more in the console. You can see the exact output in the screenshot below:

power automate get item from array variable

Read Get SharePoint Site Members Using PowerShell

Example 2: Get SharePoint Site Detailed Information

For more properties (e.g., sharing settings, last modified date), use -Detailed. This command gives detailed information for the SharePoint site collections.

Get-SPOSite -Detailed

Or

Get-SPOSite -Limit All -Detailed

You may see a warning that -Detailed will be deprecated for bulk enumeration, but it still returns a rich set of properties that are useful for reporting. Here is a screenshot below for your reference.

power automate length of array variable

Example 3: Get a Specific SharePoint Site Collection Details

If you only care about one SharePoint site, use -Identity. This example gives details for the specific SharePoint site url.

Get-SPOSite -Identity https://szg52.sharepoint.com/sites/Marketing -Detailed 

Or 

$SiteUrl = "https://yourtenant.sharepoint.com/sites/Marketing"
Get-SPOSite -Identity $SiteUrl -Detailed

This is handy when you want to quickly check template, storage usage, or sharing settings for a single SharePoint site. Check the screenshot below for your reference.

get a list of all SharePoint sites PowerShell

Check out Add SharePoint Online List Items Using PnP PowerShell

Filter SharePoint Site Collections with Get‑SPOSite

One of the best things about Get-SPOSite is the filtering capability, especially in larger tenants.

Example 4: Only SharePoint Team Sites (no Microsoft 365 group)

Classic/team sites without a group often use template STS#3. Here is the PowerShell script:

Get-SPOSite -Limit All -Filter { Template -eq "STS#3" } |
    Select Url, Template, Owner

You can see the exact output in the screenshot below:

SharePoint Tutorials

This returns only those SharePoint sites and shows their URL, template, and owner.

Check out Delete a SharePoint Online Site Using PowerShell

Example 5: SharePoint Sites not Connected to Microsoft 365 groups

To find “standalone” sites that are not group‑connected, you can use the below script:

Get-SPOSite -Limit All -GroupIdDefined $false |
    Select Url, Owner, Template

You’ll see only sites where there is no underlying Microsoft 365 group.

power automate remove characters from array

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

Check out Get SharePoint Site Storage Size Using PowerShell

Example 6: Archived SharePoint Sites Only

If you use site archiving, it’s often useful to list only archived sites. This example displays SharePoint sites of a specific archive status.

Get-SPOSite -Limit All -ArchiveStatus "Archived" |
    Select Url, Title, ArchiveStatus

This makes it easy to review which sites are archived and decide whether they can be deleted or reactivated. You can see the exact output in the screenshot below:

get all site collections in SharePoint online PowerShell

Read Get the SharePoint Site Owner Using PowerShell

Export SharePoint Site Collections to CSV with Get‑SPOSite

In real‑world scenarios, you rarely just look at site collections on screen — you export them to Excel, share with other teams, or use them for audits.

Example 7: Full tenant inventory to CSV

Here is the complete PowerShell script:

$AdminUrl = "https://yourtenant-admin.sharepoint.com"
$CsvPath  = "C:\Temp\SharePointOnline-Sites.csv"

Connect-SPOService -Url $AdminUrl

Get-SPOSite -Limit All -Detailed |
    Select Title, Url, Owner, Template, StorageUsageCurrent, StorageQuota, `
           LastContentModifiedDate, SharingCapability |
    Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8

This gives you a clean CSV with key properties for every site collection in your tenant.

Read Enable Item-level Permissions in a SharePoint Document Library Using PowerShell

Get all SharePoint Site Collections Using PnP PowerShell

PnP PowerShell is a community‑driven module that makes tenant‑level operations easier and is actively maintained for modern SharePoint.

The main cmdlet you’ll use is Get‑PnPTenantSite.

Basic syntax

Get-PnPTenantSite [-Identity] [-Detailed] [-Template] [-IncludeOneDriveSites] `
                  [-GroupIdDefined] [-Filter] [-DisableSharingForNonOwnersStatus]

Key parameters:

  • Identity – URL of a specific site collection.
  • Detailed – Returns extended properties.
  • Template – Filter by site template, similar to Get-SPOSite.
  • IncludeOneDriveSites – Include all OneDrive for Business sites in the results.
  • GroupIdDefined – $true for group‑connected sites.
  • Filter – String‑based filter, e.g., "Url -like 'sales'".
  • DisableSharingForNonOwnersStatus – Show sites where sharing for non‑owners is blocked.

Check out Get All Microsoft 365 Group Connected SharePoint Sites using PowerShell

Example 8: Get all SharePoint Online Site Collections

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

$AdminUrl = "https://yourtenant-admin.sharepoint.com"
Connect-PnPOnline -Url $AdminUrl -Interactive

Get-PnPTenantSite

This returns all SharePoint site collections (excluding OneDrive sites by default) with basic info like URL and template.

send email to sharepoint group using rest api

Example 9: Get all SharePoint Sites including OneDrive

If you need a truly complete list of all collaboration spaces including personal OneDrive sites:

Get-PnPTenantSite -IncludeOneDriveSites

Use this carefully, as OneDrive counts can be very high in large organizations.

Example 10: Get a Single SharePoint Site by URL

This example gives the specific SharePoint site Url information.

$SiteUrl = "https://yourtenant.sharepoint.com/sites/EventPlanning"
Get-PnPTenantSite -Identity $SiteUrl

This returns just that specific SharePoint site with its core properties like in the screenshot below:

how to get all site collections in SharePoint online PowerShell

Check out Upload Single or Multiple Files to SharePoint with Metadata Using PnP PowerShell

Filter tenant sites with Get‑PnPTenantSite

We can use similar filters in PnP to quickly segment our sites.

Example 11: Filter by URL

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

Get-PnPTenantSite -Filter "url -like 'Project' "

This lists all SharePoint sites that have “Project” in their URL, which is useful if you follow a naming convention.

how to get all SharePoint sites PowerShell

Example 12: Get All SharePoint Sites including OneDrive Sites

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

Get-PnPTenantSite -IncludeOneDriveSites

You can see the exact output in the screenshot below:

get a list of all SharePoint site collections using  PowerShell

Example 13: Only group‑connected SharePoint Sites

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

Get-PnPTenantSite -GroupIdDefined $true

This returns only the SharePoint sites that are backed by Microsoft 365 groups (for example, team sites created from Teams or Outlook). Here is the exact output in the screenshot below:

SharePoint Trainings

Check out How to Check SharePoint Version Using PowerShell

Export Tenant SharePoint Sites to CSV with PnP PowerShell

Just like with Get-SPOSite, you’ll often want to export the PnP results to a CSV file.

Example 13: Export all SharePoint Sites to Excel

$AdminUrl   = "https://yourtenant-admin.sharepoint.com"
$CsvPath    = "C:\Temp\PnP-AllSites.csv"

Connect-PnPOnline -Url $AdminUrl -Interactive

Get-PnPTenantSite -Detailed |
    Select Title, Url, Owner, LastContentModifiedDate, WebsCount, Template, StorageUsage |
    Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8

This script gives you a detailed report with SharePoint site counts, last activity date, and storage usage, which is perfect for governance and cleanup projects.

When to use Get‑SPOSite vs Get‑PnPTenantSite

Both cmdlets can give you a list of all SharePoint Online site collections, but they have slightly different strengths.

ScenarioUse Get‑SPOSiteUse Get‑PnPTenantSite
You prefer Microsoft‑built modulesYesMaybe
You want modern, cross‑platform automationLimitedYes (PowerShell 7, cross‑platform)
You need to include OneDrive sitesIncludePersonalSiteIncludeOneDriveSites
You already use PnP for other scriptsNot requiredBest choice
You need rich tenant‑wide reportingGoodExcellent with -Detailed

Best Practices

Here are some best practices you can follow while working with PowerShell to get SharePoint site collections.

  • Always use the admin center URL for tenant‑level operations (https://yourtenant-admin.sharepoint.com).
  • Prefer -Limit All with Get-SPOSite when you truly need a complete list; otherwise, large tenants might appear incomplete.
  • Use Select to keep only the columns you actually need; this makes CSV files smaller and easier to read.
  • Store CSV files in a secure location, as site URLs and owners are often considered sensitive.

In this tutorial, we discussed how to get all the SharePoint site collections using PnP PowerShell. We saw a lot of examples including PnP PowerShell cmdlets.

You may also like the following tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…