PowerShell script to find the Count of number of items in a list in a web application

Here is the PowerShell script to loop through all the site collections and sites to list out the number of items in a list /library. Output is saved as a csv file.

Save the below script as .ps1 before executing. While running the script enter the URL of the web application and the location to save the output file when requested in the powershell prompt.

This script may not work in all environments or may not be accurate.

#Url of the web application
Write-host “Enter the web application URL:”
$url = Read-Host

#Output file location
Write-host “Enter the location to save the output file:(C:\Temp\Filename.csv)”
$OutputFile = Read-Host

#Variable for results
$result = @()

#Get the web application reference

$webApplication = Get-SPWebApplication $url

foreach($webApp in $webApplication)
{
         #loop through all the site collections
          foreach($siteCollection in $webApp.Sites)
         {
                   #loop throgh all the sites
                   foreach($web in $siteCollection.AllWebs)
                 {
                        $webUrl = $web.url
                        $lib = $web.Lists | Where-Object {1}
                        $lib | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
                        $results += ($lib | Select-Object -Property WebUrl, Title, ItemCount)
                 }
          }
}

$result | Export-Csv -Path $OutputFile

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

SharePoint Designer cannot display the item

You run into ‘SharePoint Designer cannot display the item’ error when you are trying to edit an existing workflow setup in Designer quite often when there is a windows update or update to .NET framework installed in your computer. In some cases it may also not allow you to create new workflows. Resolution: Clearing Designer […]

Read More

Windows security prompt. Connecting to SharePoint….

Users often run into this issue. Windows security prompt pops up every 15 minutes or so repeatedly trying to connect to SharePoint. No matter you enter credentials or cancel, user will be prompted for credentials again and again. SharePoint may not be the culprit all the time. List of things I check whenever I run […]

Read More

User with Contribute access gets access denied

Only one user with contribute access gets access denied to SharePoint site collection. Every SharePoint admin might have faced this issue atleast once. In my case, user is added to a SharePoint group with Contribute access. Access shows up as Contribute when verified through site permissions – check permission option. Every other person in the […]

Read More