0

I'm struggling with weird issue, I'm trying to get the items from a list on a sharepoint Site, I made a very simple script for testing purpose:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL = "https://mysharepointsite.com"
$listName = "Users"

$list = (Get-SPWeb $WebURL).Lists.TryGetList($ListName)
 
$items = $list.GetItems()


Write-Host $items.Count
write-Host $list.ItemCount

So my list exist and it contains 27 items (I check that manually), the $items.count return a null value but $list.itemCount returns 27 If I tried with another list on the same site, everything works perfectly, any idea of what I'm doing wrong?

Thanks for your help

1

Permissions could be the issue. As SharePoint provide item level permission, to use $list.GetItems() make sure you have permissions to the list items.

Reference: https://mywaysharepoint.wordpress.com/2015/05/23/difference-between-splist-itemcount-and-splist-items-count/

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.