Get All List and Libraries Inventory of a SharePoint Site Collection using PowerShell

Requirement: Get All Lists and Libraries Inventory of a SharePoint Site Collection

PowerShell to Get Site Collection List and Library Inventory:

If you’ve ever needed to get a comprehensive inventory of all the lists and libraries in a SharePoint site, PowerShell is the way to go! In this blog post, we will look at how to get a list and library inventory of a SharePoint site using PowerShell. We’ll also see how to get a detailed list of everything that’s available for each site collection in a web application.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection Variable
$SiteURL="https://intranet.crescent.com"
$ReportOutput="C:\SiteInventory.csv"

#Get the site collection
$Site = Get-SPSite $SiteURL

$ResultData = @()
#Ge All Sites of the Site collection
Foreach($web in $Site.AllWebs)
{
    Write-host -f Yellow "Processing Site: "$Web.URL
 
    #Get all lists - Exclude Hidden System lists
    $ListCollection = $web.lists | Where-Object  { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false)}

    #Iterate through All lists and Libraries
    ForEach ($List in $ListCollection)
    {
            $ResultData+= New-Object PSObject -Property @{
            'Site Title' = $Web.Title
            'Site URL' = $Web.URL
            'List-Library Name' = $List.Title
            'Item Count' = $List.ItemCount
            'Created By' = $List.Author.DisplayName
            'Last Modified' = $List.LastItemModifiedDate.ToString();
            'List URL' = "$($Web.Url)/$($List.RootFolder.Url)"
            } 
    } 
}

#Export the data to CSV
$ResultData | Export-Csv $ReportOutput -NoTypeInformation

Write-host -f Green "Report Generated Successfully at : "$ReportOutput

This script exports the results to a CSV file for further analysis, which can be helpful for troubleshooting or auditing purposes.

Report Output: 

Get All List and Libraries Inventory of a SharePoint Site Collection using PowerShell

Get Lists and Libraries Inventory for All Site Collections in a Web Application

Before running the script, make sure you add a web application user policy with Full control for the web application.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Parameters
$WebAppURL="https://intranet.sharepoint.com"
$ReportOutput="C:\Temp\SiteInventory.csv"

#Delete the Output report file if exists
If (Test-Path $ReportOutput) { Remove-Item $ReportOutput }
 
#Get all site collections from the web application
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL -PipelineVariable Web | ForEach-Object {
    Write-host -f Yellow "Processing Site: "$Web.URL
  
    #Get all lists - Exclude Hidden System lists
    $ListCollection = $Web.lists | Where-Object  { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false)}
    
    $ResultData = @()
    #Iterate through All lists and Libraries
    ForEach ($List in $ListCollection)
    {
            $ResultData+= New-Object PSObject -Property @{
            'Site Title' = $Web.Title
            'Site URL' = $Web.URL
            'List/Library Name' = $List.Title
            'Item Count' = $List.ItemCount
            'Created By' = $List.Author.DisplayName
            'Last Modified' = $List.LastItemModifiedDate.ToString();
            'List URL' = "$($Web.Url)/$($List.RootFolder.Url)"
            }
    }

    #Append data to CSV
    $ResultData | Export-Csv $ReportOutput -NoTypeInformation -Append
}
Write-host -f Green "Report Generated Successfully at: "$ReportOutput

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

14 thoughts on “Get All List and Libraries Inventory of a SharePoint Site Collection using PowerShell

  • Is it possible to add ModifiedBy field in there?

    Reply
  • Does this work for On-Prem sites? I’ve been trying to use this to get the information so I can work on migrating everything from On-Prem Classic sites to SPO Modern, but I keep getting an error with the ‘Get-SPSite’ cmdlet when I run the code. Error says something about “this is not a recognized function, cmdlet, etc…”

    Reply
    • Make sure you are running this from SharePoint Server (Not from your local machine!).

      Reply
  • A/S Salaudeen
    I want to generate and site wise report for SP2007 which generates an output with all the sites(all level of subsites) in a site collection along with Storage/last modified/site owner
    can you please help me with the PS for that?
    -Ahad

    Reply
  • Thank you Sal. Could I ask a question please? I want to iterate through all site collections (SharePoint Online) and find all promoted links lists (id 170 I believe). Part of a migration project and we are doing like for like copy. Thanks again love your stuff

    Reply
  • Thank you helped me a lot

    Reply
  • Will it be able to run the script for number of sites together rather individual.
    As an example: if have 200 sits
    https://intranet.crescent.com/site/siteA
    https://intranet.crescent.com/site/siteB

    Reply
    • Thank you for the reply. Unfortunately it giving me list of libraries in root level not the site level:
      https://intranet.crescent.com/site/…..
      what can be the reason?

      Reply
  • @Sal :Thank you so much for your great contribution to SharePoint folks…because of your script i saved my time..!

    Reply
  • Thank you and good work!

    Reply
  • Can you please help me to generate this report in SharePoint Online?

    Reply

Leave a Reply