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 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
Get All List and Libraries Inventory of a SharePoint Site Collection using PowerShell Get All List and Libraries Inventory of a SharePoint Site Collection using PowerShell Reviewed by Salaudeen Rajack on March 30, 2017 Rating: 5

7 comments:

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

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

    ReplyDelete
  3. 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

    ReplyDelete
    Replies
    1. Sure, Script added to get list inventory from all sites in a web application.

      Delete
    2. 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?

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.