Friday, 11 March 2016

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
}}}

Advertisements
Advertisements

2 comments:

  1. Hi there,
    thanks for sharing the script, i need to get list itemcount as well, to show in each library or list how many items we have. can you please help me with this too.
    Regards

    ReplyDelete
    Replies
    1. Hope you can get total available list items using the list property "ItemCount"

      $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
      TotalItems += $_.ItemCount
      }}}

      Refer this thread : https://social.technet.microsoft.com/Forums/en-US/f35cb3fa-f788-424a-9e91-317d8e374765/powershell-script-to-count-number-of-list-and-library-items-in-site-collection?forum=sharepointadminprevious

      Delete