Get all lists in a Sharepoint Site using Powershell

In this article, I am going to write powershell script to find all lists and libraries in a SharePoint site. The following powershell script find and displays all lists from the given SharePoint site. You need to replace your own site url.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
$Site = Get-SPSite "http://MySharePointWeb:81/"
# get the all sub sites of site
$SubSites = $Site.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
}}}

Get all Document Libraries in a SharePoint site

The below powershell script find and lists all the document libraries from a given sharepoint site. You just need to change the BaseType filter in the above query to get document libraries.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$Site = Get-SPSite "http://MySharePointWeb:81/"
# get the all sub sites of site
$SubSites = $Site.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
}}}

Advertisement

Leave a Comment