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:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection Variable
$SiteURL="http://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

Report Output: 

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

Get 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="http://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

  • October 12, 2021 at 8:20 AM

    Is it possible to add ModifiedBy field in there?

    Reply
  • October 1, 2021 at 9:57 PM

    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
    • October 5, 2021 at 9:48 PM

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

      Reply
  • April 10, 2021 at 11:01 AM

    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
  • February 7, 2021 at 6:28 PM

    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
  • October 26, 2020 at 11:33 AM

    Thank you helped me a lot

    Reply
  • May 5, 2020 at 4:50 AM

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

    Reply
    • May 6, 2020 at 11:07 PM

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

      Reply
  • April 9, 2020 at 7:08 PM

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

    Reply
  • May 22, 2019 at 10:35 AM

    Thank you and good work!

    Reply
  • April 10, 2019 at 12:50 PM

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

    Reply

Leave a Reply