Every SharePoint cleanup I’ve run starts with the same question: how many sites do we actually have? The admin center shows them, but you can’t easily filter by template, join the list with storage numbers, or hand a CSV to the person who has to chase site owners.
PnP PowerShell answers that in a few lines. I tested everything below on my own Microsoft 365 tenant in PowerShell 7 with PnP.PowerShell 3.3: listing every site collection, filtering by template and URL, adding OneDrive sites, finding subsites and exporting the result.
Quick answer: Connect to the SharePoint admin center, not a site: Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -ClientId <your-app-id> -Interactive. Then run Get-PnPTenantSite to return every site collection (OneDrive excluded). Add -Template, -Filter "Url -like 'sales'" or -IncludeOneDriveSites to narrow or widen the list, and pipe it to Export-Csv for a report.
What you need before you start
Get-PnPTenantSite reads tenant-level data, so a regular site member can’t run it. Check these three things first. If PnP isn’t on your machine yet, follow my guide on installing PnP PowerShell for SharePoint Online.
- PowerShell 7.4 or later with the PnP.PowerShell module. Current PnP versions don’t load in Windows PowerShell 5.1.
- The SharePoint Administrator or Global Administrator role. The cmdlet runs against the tenant administration site.
- Your own Entra ID app registration for the
-ClientIdparameter. The shared PnP app stopped working on September 9, 2024, which is why older scripts without a client ID fail.
If you landed here from an older tutorial and saw an error about Register-PnPManagementShellAccess, that’s the same retired app; my post on the Register-PnPManagementShellAccess error explains the switch.
Get all site collections with Get-PnPTenantSite
Connect to the admin center URL, which is your tenant name followed by -admin, then call the cmdlet with no parameters. I store the result in a variable so I can count, group and filter it without asking SharePoint again:
$adminUrl = "https://contoso-admin.sharepoint.com"
$clientId = "00000000-0000-0000-0000-000000000000" # your Entra ID app's client ID
Connect-PnPOnline -Url $adminUrl -ClientId $clientId -Interactive
$sites = Get-PnPTenantSite
"Site collections found: $($sites.Count)"
Here’s the real run on my tenant. Grouping by template is the fastest way to see what kind of sites you have before you filter anything:

Each object includes Title, Url, Template, Owner, StorageUsageCurrent (in MB) and LastContentModifiedDate. Some properties come back with default values unless you add -Detailed, which fills in every attribute but runs noticeably slower on a large tenant.
For one site, pass its URL: Get-PnPTenantSite -Identity https://contoso.sharepoint.com/sites/Marketing -Detailed. Modern sites can also be looked up by their site ID.
Filter sites by template: team sites, communication sites and more
The Template value tells you what kind of site each one is. These are the codes I saw in my tenant, and they’re the ones you’ll meet most often. If the difference between the first two is fuzzy, read my comparison of team sites and communication sites.
| Template | What it is |
|---|---|
| GROUP#0 | Team site connected to a Microsoft 365 group (including sites created by Microsoft Teams) |
| SITEPAGEPUBLISHING#0 | Communication site |
| STS#3 | Modern team site without a Microsoft 365 group |
| STS#0 | Classic team site (often the tenant root site on older tenants) |
| TEAMCHANNEL#0 / #1 | Site for a Teams private or shared channel |
| RedirectSite#0 | Redirect left behind when a site URL was changed |
| SRCHCEN#0, APPCATALOG#0, SPSMSITEHOST#0 | System sites: search center, app catalog, OneDrive host |
Pass a template to -Template and SharePoint filters on the server, which is faster than pulling everything and filtering locally:
# Communication sites
Get-PnPTenantSite -Template SITEPAGEPUBLISHING#0
# Team sites connected to a Microsoft 365 group (includes Teams team sites)
Get-PnPTenantSite -Template GROUP#0
# Any site with a Microsoft 365 group behind it
Get-PnPTenantSite -GroupIdDefined $true
# Classic-style team sites without a group
Get-PnPTenantSite -Template STS#3
In my tests the template value wasn’t case-sensitive: SITEPAGEPUBLISHING#0 returned the root site even though it reports SitePagePublishing#0.
Filter sites by URL or other properties
-Filter takes a server-side expression. With -like, the value matches anywhere in the URL, so 'Power' also caught my PnPPowerShell site. Here I also drop redirect sites and pick the columns I care about:

Watch the operator case. "Url -like 'Power'" returned 11 sites, while "Url -LIKE 'Power'" failed with Syntax error in the filter expression. Microsoft documents the same rule for Get-SPOSite: filter operators are case-sensitive.
For anything the server filter can’t express, filter in PowerShell. This drops system and redirect sites, then finds sites with no content changes in 2026, a good starting list for an archive review. To see where space goes inside one site, check document library size with PnP PowerShell.
$skip = 'RedirectSite#0', 'RedirectSite#1', 'SRCHCEN#0', 'APPCATALOG#0',
'SPSMSITEHOST#0', 'POINTPUBLISHINGHUB#0', 'POINTPUBLISHINGTOPIC#0'
$sites = Get-PnPTenantSite | Where-Object { $_.Template -notin $skip }
# Sites nobody has touched since January 1, 2026
$sites | Where-Object LastContentModifiedDate -lt ([datetime]'01/01/2026') |
Select-Object Title, Url, LastContentModifiedDate
Include OneDrive for Business sites
OneDrive sites are site collections too, but Get-PnPTenantSite leaves them out by default. On my tenant, adding -IncludeOneDriveSites raised the count from 159 to 173. Every OneDrive for Business URL contains the user’s name, so treat that output as personal data:
# All sites plus every user's OneDrive
Get-PnPTenantSite -IncludeOneDriveSites
# OneDrive sites only
Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
Export all SharePoint sites to a CSV file
Most of the time the list goes to someone else, so I export it. Select the columns first; otherwise Export-Csv writes every property, including a lot of empty ones:

Add Owner to the selection when you need contacts for each site. For a storage report, sort by StorageUsageCurrent and compare it with your default storage limit for new sites.
Get subsites in every site collection with Get-PnPSubWeb
Get-PnPTenantSite returns site collections only. Older intranets often have subsites created under a site, and those need a second step: connect to each site and run Get-PnPSubWeb -Recurse, which also returns nested subsites.
$clientId = "00000000-0000-0000-0000-000000000000"
Connect-PnPOnline -Url "https://contoso-admin.sharepoint.com" -ClientId $clientId -Interactive
$sites = Get-PnPTenantSite | Where-Object Template -notlike 'RedirectSite*'
$report = foreach ($site in $sites) {
try {
$conn = Connect-PnPOnline -Url $site.Url -ClientId $clientId -Interactive -ReturnConnection
$subs = @(Get-PnPSubWeb -Recurse -Connection $conn -ErrorAction Stop)
foreach ($web in $subs) {
[pscustomobject]@{ SiteCollection = $site.Url; Subsite = $web.Url; Title = $web.Title }
}
}
catch {
Write-Warning "Skipped $($site.Url): $($_.Exception.Message)"
}
}
$report | Export-Csv -Path ".\Subsites-2026-10-13.csv" -NoTypeInformation
-ReturnConnection keeps each site connection separate, and the token is reused, so you sign in once. The try/catch matters: in my run, one site threw Attempted to perform an unauthorized operation. Being a SharePoint admin doesn’t make you a member of every site; add yourself as a site admin first if you need everything.
Troubleshooting Get-PnPTenantSite errors
The error I see most comes from connecting to a regular site and then asking for tenant data:

- “We do not support automatically switching context to the tenant administration site”: device login (and some other sign-in types) can’t switch to the admin site for you. Connect to
https://contoso-admin.sharepoint.comdirectly. - Access denied or 403 Forbidden: your account lacks the SharePoint Administrator role, or an app-only connection lacks tenant-wide SharePoint application permissions. The same root cause is behind the Connect-SPOService 403 Forbidden error.
- Fewer sites than you expected: OneDrive sites only appear with
-IncludeOneDriveSites, and a-Templateor-Filterleft over from an earlier command narrows the list. - Syntax error in the filter expression: write the operator in lowercase (
-like, not-LIKE) and wrap the value in single quotes inside the double-quoted filter.
PnP PowerShell vs Get-SPOSite
The SharePoint Online Management Shell does the same job with Get-SPOSite. One difference catches people: it returns only 200 sites unless you add -Limit All, and it uses -IncludePersonalSite $true for OneDrive sites. I prefer PnP because the same session can go on to lists, files and permissions, as in my PnP PowerShell scripts for SharePoint developers.
Connect-SPOService -Url https://contoso-admin.sharepoint.com
Get-SPOSite -Limit All | Select-Object Title, Url, Template, StorageUsageCurrent
Once you have the site list, these PnP PowerShell guides help with the next step:
Frequently Asked Questions
How do I get all SharePoint Online sites using PnP PowerShell?
Connect to your admin center with Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -ClientId -Interactive, then run Get-PnPTenantSite. It returns every site collection except OneDrive sites.
Does Get-PnPTenantSite include OneDrive sites?
Not by default. Add -IncludeOneDriveSites, or combine it with -Filter “Url -like ‘-my.sharepoint.com/personal/'” to get OneDrive sites only. The Get-PnPTenantSite reference lists every parameter.
What permissions do I need to run Get-PnPTenantSite?
You need the SharePoint Administrator or Global Administrator role, or an app-only connection with tenant-wide SharePoint application permissions, because the cmdlet reads the tenant administration site.
How do I get only communication sites or team sites?
Use -Template SITEPAGEPUBLISHING#0 for communication sites, -Template GROUP#0 for Microsoft 365 group team sites, and -Template STS#3 for team sites without a group.
Does Get-PnPTenantSite return subsites?
No, it returns site collections only. Connect to each site and run Get-PnPSubWeb -Recurse to list subsites. Microsoft’s Get-SPOSite reference covers the equivalent admin module cmdlet.

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.