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 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
Retrieving an inventory of all lists and libraries in a SharePoint site collection is a common task. PowerShell makes it easy to retrieve an inventory of all lists and libraries within a SharePoint site collection using a few steps. Save your time and effort with the scripts provided in this article!
If you want to generate an inventory of all documents in a site, use: Get Documents Inventory for a Site Collection using PowerShell
how would we include the Information Management Retention setting for the library if one is configured or not?
Is it possible to add ModifiedBy field in there?
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…”
Make sure you are running this from SharePoint Server (Not from your local machine!).
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
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
Thank you helped me a lot
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
Sure, Script added to get list inventory from all sites in a web application.
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?
@Sal :Thank you so much for your great contribution to SharePoint folks…because of your script i saved my time..!
Thank you and good work!
Can you please help me to generate this report in SharePoint Online?
Here you go: SharePoint Online PowerShell script to get lists and libraries report
can we get title only once