2

Just for clarifying, I have written following two lines in Powershell script and see output as:

$web = Get-SPWeb http://intranet;

$list = $web.GetList("documents");
$items = $list.items;

i see these out puts in Powershell

$list.itemcount returns 56 but $items.count returns 23, why ?
9

AS PER MSDN

SPList.ItemCount:

The value of the ItemCount property includes folders within a document library, as well as files within subfolders. The value of the Count property of the SPListCollection class does not include folders.

SPListItemCollection.Count:

Gets the number of list items in the collection, excluding folders.

BUT

Although it's clear there, that the folders are included with ItemCount, but not for Items.Count, there is another more subtle difference - if you are running code in a user context, you will see that the Items collection is security- trimmed, and its count is therefore only for those items the user can see. On the other hand, ItemCount does not appear to be security trimmed.

ALSO

ItemCount is faster because it gets a static SPList property instead of building the SPListItemCollection object before counting its members.

Reference

SPList.ItemCount is not the same as SPList.Items.Count

  • +1 for pointing out that the item collection is security trimmed, very important to keep in mind. – Dylan Cristy Nov 19 '14 at 14:58
0

$list.itemcount counts the folders also

while $items.count counts the list items

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.