How do I get the number of items in a SharePoint list using PowerShell?

Today I will share a short script for getting totals from a list view in SharePoint. Imagine this scenario: you have set up a list view with totals and you want get the totals every day for statistics or some other reasons. Instead of getting all items, and/or fiddling around with CamlQueries, there is a better and quicker way List.RenderListData. This combined with a tip from Piyush K Singhs blog post Get Aggregate Values I came up with an idea to read the ViewXml from an existing view and retrieve the totals [in my case Count and Sum]. Enough talking, lets take a look at the code:

The good part of that approach is that you can let your view evolve over time and work together with colleagues on that, your script does not need an update every time you change the view. The only thing it alters is the RowLimit thats for better performance. Why load 30 or more list items when 1 is enough.

I have tested it in SharePoint 2013 and SharePoint Online.

Video liên quan

Chủ Đề