How to get the list of List and Document library item counts in SharePoint online using Pnp Powershell ?

Hello SharePointers,

Below are the powershell commands to get the list of List and Document library item counts in SharePoint online using Pnp Powershell .

$siteurl = "https://organisation.sharepoint.com/sites/selfservice/"
$credentials = Get-Credential
Connect-PnPOnline -Url $siteurl -Credentials $credentials

$Subsites= Get-PnPSubWebs
$ListItemCollection = @()

Write-Host “Subsite count is ” $Subsites.Count ” in the site”

foreach ($subsite in $Subsites)
{
Write-Host $subsite.Title
 Connect-PnPOnline -Url $subsite.Url -Credentials $credentials
$Lists= Get-PnPList |Where-Object {$_.Title -ne 'Form Templates' -and $_.Title -ne 'Site Assets' -and $_.Title -ne 'Style Library'} 

Write-Host “Subsite name is ” $Subsite.Title” in the site”
foreach ($list in $Lists)
{

$row = new-object PSObject
Add-member -inputObject $row -memberType NoteProperty -Name “Site Name” -value $Subsite.Title
Add-member -inputObject $row -memberType NoteProperty -Name “URL” -value $list.RootFolder.ServerRelativeUrl
Add-member -inputObject $row -memberType NoteProperty -Name “List Title” -value $list.Title
Add-member -inputObject $row -memberType NoteProperty -Name “List Item Count” -value $list.ItemCount
Add-member -inputObject $row -memberType NoteProperty -Name “Last Modified Date” -value $list.LastItemModifiedDate
 $ListItemCollection += $row
}
}
 #Export the result Array to CSV file
 $ListItemCollection | Export-CSV "D:\ListData.csv" -NoTypeInformation       





Happy SharePoint folks

Leave a Reply

Your email address will not be published.