Get count of SharePoint List or Document Library Items using PowerShell

PowerShell script/code to get SharePoint List Item count

The same script works for both lists and libraries. You can add filters to get only specific items.

It is recommened to use variables so you can quickly modify the values and reuse script for any other site, list, library.

$siteUrl = "http://siteurl"
$listName = "[Name of List/Library]"
$spWeb = Get-SPWeb $siteUrl
$spList= $spWeb.Lists[$listName]

$items = $spList.Items.Count

The var $items will get the count value (Items.Count). Print the value to verify and then you can use it further in your logic.

Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.