ExpertiseKnowledgeToolsField GuideBlogAbout
← pH7x KnowledgeSharePoint

How to enumerate every site in a SharePoint tenant

What sites exist in this tenant, as far as I can see?

By João Livio·pH7x Knowledge

30-second answer

powershell
$appId = 'your Entra ID app registration id'
Connect-PnPOnline -Url https://contoso-admin.sharepoint.com `
  -Interactive -ClientId $appId
Get-PnPTenantSite | Select-Object Url, Template, StorageUsageCurrent

Connect to the admin centre, not to a site.

What this proves

The site collections this identity can enumerate, with their tenant-level properties: template, storage, sharing capability, lock state, group id. This is the inventory every tenant-wide question starts from.

What it does not prove

  • That the list is the tenant. The count is a lower bound. On a real tenant, a delegated identity enumerated 53 sites and could then read evidence from only 47; six refused with an authorization error. An account with different rights sees a different list, and nothing in the output marks the difference.
  • Anything about subsites. Get-PnPTenantSite returns site collections; webs inside them are a per-site question.
  • OneDrive, unless asked. Personal sites need -IncludeOneDriveSites, and appear only for identities allowed to see them.

PowerShell

powershell
$sites = Get-PnPTenantSite
"{0} site collections enumerable by this identity" -f $sites.Count
$sites | Group-Object Template | Sort-Object Count -Descending |
  Select-Object Count, Name

Example output

text
53 site collections enumerable by this identity

Count Name
----- ----
   22 GROUP#0
   14 SITEPAGEPUBLISHING#0
    9 STS#3
    8 TEAMCHANNEL#1

Explanation

The template distribution is the fastest honest summary of what a tenant is: GROUP#0 sites are group-connected team sites, SITEPAGEPUBLISHING#0 are communication sites, STS#3 are modern team sites without a group, and TEAMCHANNEL#1 belong to Teams channels. Always report the count as "enumerable by this identity" rather than "the tenant", because that phrasing is the difference between evidence and a guess.

Production considerations

  • Requires a SharePoint administrator role and the https://<tenant>-admin.sharepoint.com connection.
  • Large tenants return thousands of rows; filter server-side where the cmdlet's parameters allow it before resorting to Where-Object.
  • Deleted sites in the recycle bin are not returned; they still exist and still hold content.

References