Share via


How to count number of pages in site collection and sub-sites on SharePoint online

Question

Thursday, October 6, 2016 1:47 PM

Hi,

Using powershell script How to get a report like number of pages in site collection and sub-sites on SharePoint online .

How i can count the number of pages under a site collection/subsites?

Please suggest 

All replies (4)

Friday, October 7, 2016 6:33 PM ✅Answered

Hello,

The link above is for on premises so it will not work in online.

Now, in online, you can modify the below code as per your environment to extract this information for a site:

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.aspx

For the list name, put your Pages library name.

Since CSOM does not have any property at site level to enumerate all webs, you either need to do the task individually, or note down the URLs in a list, and enumerate through the items to read and execute

For anything related to SharePoint https://www.fiverr.com/rashu268


Friday, October 7, 2016 8:27 PM ✅Answered

Here are the two options

  1. Use the Search REST Api, search for all items matches the Page content type and use the Total Row count from the response. Can I use the REST api in PowerShell? Yes you can. Pros - No need to recursively look into all the sub sites and its libraries. Cons - Only approved, published and indexed will be counted (Since its SPO I don't see a reason for the pages not getting indexed)
  2. You need to use PowerShell CSOM - Use the libraries like PnP PowerShell, write a recursive logic to iterate through each sub sites and its libraries and then make a CAML query over the library and then get the count.

I would prefer option 1.

Rajesh
rjesh.com| @rjesh
You don't need to buy me a beer, if helpful just smile, vote, and mark it as answer.


Friday, October 7, 2016 5:56 PM

Hi Gayam- see the following link for a sample script and instructions:

http://www.superedge.net/2012/08/how-to-count-how-many-pages-in.html

cameron rautmann


Friday, October 7, 2016 6:21 PM

Hi,

Here you go

http://sharepoint.stackexchange.com/questions/114947/how-to-count-number-of-pages-in-sharepoint-site-using-powershell

Please remember to click Mark as Answer on the answer if it helps you