Get all lists in a SharePoint Web Application using Powershell

In this article, I am going to write powershell script to find all lists and libraries in a SharePoint farm server. The following powershell script export all lists from a SharePoint web application to csv file. You need to replace your own web application url.

Add-PSSnapin Microsoft.SharePoint.PowerShell
 
$SPWebApp = Get-SPWebApplication "http://MySharePointWeb:81/" -ErrorAction SilentlyContinue
# get all the site collections
$SiteCollections = $SPwebApp.Sites
$SiteCollections | ForEach-Object { 
# get the all sub sites of site collection
$SubSites = $_.AllWebs
$SubSites | ForEach-Object { 
$Site = $_
# get all lists from site
$lists = $Site.Lists | Where-Object { $_.BaseType -eq 'GenericList' }
$lists | ForEach-Object {                 
    New-Object -TypeName PSObject -Property @{
              ListName = $_.Title
              SiteName = $Site.Title
              SiteUrl = $Site.Url
}}}}| Export-CSV "C:\All-Lists.csv" -NoTypeInformation -Encoding UTF8

Get all Document Libraries in a SharePoint web application

The below powershell script find and export all the document libraries from a SharePoint web application to csv file. You just need to change the BaseType filter in the above query to get document libraries.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SPWebApp = Get-SPWebApplication "http://MySharePointWeb:81/"
# get all the site collections  
$SiteCollections = $SPwebApp.Sites
$SiteCollections | ForEach-Object { 
# get the all sub sites of site collection
$SubSites = $_.AllWebs
$SubSites | ForEach-Object { 
$Site = $_
 # get all document Libraries from site
$lists = $Site.Lists | Where-Object { $_.BaseType -eq 'DocumentLibrary' }
$lists | ForEach-Object {                                     
    New-Object -TypeName PSObject -Property @{
              LibraryName = $_.Title
              SiteName = $Site.Title
              SiteUrl = $Site.Url
}}}}| Export-CSV "C:\All-Libraries.csv" -NoTypeInformation -Encoding UTF8

Advertisement

Leave a Comment