Count All List/Libraries Items Using PowerShell SharePoint 2013

This PowerShell Script will output all items count inside the provided Site Collections list. It will traverse through Site Collections then all sub sites then all list/libraries and output result in a csv file.

1.Site Collections File

Create text file with name “SiteCollections.txt” in the same directory where script file is present.
Write site collections urls in “SiteCollections” file. 
Make it sure each url should be in new line and write “End Point” at the end as shown below.


2.Open SharePoint 2013 Management Shell


3.Change directory path where script file is saved


Then type ./ItemsCounter.ps1 and press enter key.


It will count all the items of all lists and libraries in site collections which you will provide in “SiteCollection.txt” in first step.

4.Result 
Result will be saved in “ItemsCounter.csv” file which you can find in the same directory where your script file is located.
 You can also track the complete log file (named ItemsCounter-current date and time) which you can find in the same directory where your script file is located. Here is how the result will look like.




PowerShell Script

$currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."}
New-Item $PSScriptRoot\ItemsCounter-$currentTime.txt -type file
New-Item $PSScriptRoot\ItemsCounter.csv -type file -Force
$outputFile = "$PSScriptRoot\ItemsCounter.csv"
Write-Output $outputFile
$outputHeader = "siteCollection URL" + "`t" + "Site Url" + "`t" +" List Name" + "`t" + " Total Items " > $outputFile
$SiteCollectionArray =  Get-Content -Path $PSScriptRoot\SiteCollections.txt

Start-Transcript -Path "$PSScriptRoot\ItemsCounter-$currentTime.txt"

foreach($site in $SiteCollectionArray)
{
    if($site -ne "End Point") {
    $siteCollection = Get-SPSite -Identity $Site
    foreach($SPWeb in $siteCollection.AllWebs)
        {
       
            foreach($SPList in $SPWeb.Lists)
            {
          
                $TotalItems = $SPList.ItemCount
                $output = $Site + "`t" + $SPWeb + "`t" + $SPList + "`t" +  $TotalItems 
                Write-Output $output >> $outputFile
                Write-Output $output
            }

         }  
                   
      }
  }
       
   Stop-Transcript




Comments

Popular Posts

GREYCstoration Oil Paint plugin for Photoshop

Service Bus Gateway service stuck at Starting

PowerApps SubmitForm not clearing People Picker value

Apple iPhone sending SMS automatically 00447786205094

SharePoint online hub navigation not updating for other users