ExpertiseKnowledgeToolsField GuideBlogAbout
← pH7x KnowledgeSharePoint

How to enumerate modern pages on a SharePoint site

How many pages of this site are modern, and how many are not?

By João Livio·pH7x Knowledge

30-second answer

powershell
$modern = @(Get-PnPPage)
$library = Get-PnPList -Identity 'SitePages'
"{0} modern, {1} in the library" -f $modern.Count, $library.ItemCount

Two counts from two sources. Get-PnPPage returns the pages it can read as modern client-side pages; the library item count is everything in Site Pages.

What this proves

How many pages the modern page API returns for this site, and how many items the Site Pages library holds in total. The difference is an upper bound on pages that are something else.

What it does not prove

  • The difference is not "classic pages". A page can be absent from Get-PnPPage for reasons other than being classic: it may be unreadable to your identity, or not a page at all (folders and templates live in the same library). The honest name for the difference is "in the library and not returned as modern".
  • Nothing about subsites. Both calls answer for the connected web only.

PowerShell

powershell
$modern = @(Get-PnPPage)
$inLibrary = (Get-PnPList -Identity 'SitePages').ItemCount
$rest = [math]::Max($inLibrary - $modern.Count, 0)

[pscustomobject]@{
    Modern              = $modern.Count
    InLibrary           = $inLibrary
    NotReturnedAsModern = $rest
}

Example output

text
Modern InLibrary NotReturnedAsModern
------ --------- -------------------
     9        11                   2

Explanation

Reconcile the counts before believing either. On a real tenant, one site reported 9 pages in the library while the page API could inspect 8 and failed on 7 of them: numbers that cannot all be true at once. When the parts do not add up to the whole, the correct reading is that the collection is invalid, not that the site has negative classic pages. Arithmetic that cannot be true is a finding about the collector.

Production considerations

  • Get-PnPPage reads each page; on large Site Pages libraries this is many requests, not one. Consider date filters when sweeping a tenant.
  • Site read access is enough for both calls.
  • Folders in Site Pages count toward ItemCount. Expect small, explainable differences even on healthy modern sites.

References