Get all SharePoint lists by using PowerShell


My last article explained how you can retrieve all your workflows from your SharePoint 2010 farm. After this, I got some requests from people that wanted an overview of all their used lists in SharePoint 2010.

For this, I adjusted my last script a little to output all your SharePoint lists and libraries. Or you can specify the -URL parameter to get just the lists from the particular site.

param
(
[string] $URL,
[boolean] $WriteToFile = $true
)

#Get all lists in farm
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Counter variables
$webcount = 0
$listcount = 0

if($WriteToFile -eq $true)
{
$outputPath = Read-Host "Outputpath (e.g. C:\directory\filename.txt)"
}
if(!$URL)
{
#Grab all webs
$webs = (Get-SPSite -limit all | Get-SPWeb -Limit all -ErrorAction SilentlyContinue)
}
else
{
$webs = Get-SPWeb $URL
}
if($webs.count -ge 1 -OR $webs.count -eq $null)
{
    foreach($web in $webs)
    {
   #Grab all lists in the current web
    $lists = $web.Lists   
    Write-Host "Website"$web.url -ForegroundColor Green 
    if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value "Website $($web.url)"}
        foreach($list in $lists)
        {
            $listcount +=1  
            Write-Host " – "$list.Title          
            if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value " – $($list.Title)"}
        }
    $webcount +=1
    $web.Dispose()
    }
#Show total counter for checked webs & lists
Write-Host "Amount of webs checked:"$webcount
Write-Host "Amount of lists:"$listcount
}
else
{
Write-Host "No webs retrieved, please check your permissions" -ForegroundColor Red -BackgroundColor Black
}

You can run the script by running the .ps1 file. There are 2 parameters that you can add.

WriteToFile: Default is true. If the parameter is set to true, the console will ask for a output location where the text file will be saved.
URL: Default is empty. If the URL Parameter is set, only the web you specified and all webs under this web will be reported.

Here is a possible outcome:

image

Advertisements

14 thoughts on “Get all SharePoint lists by using PowerShell

    • Hi Chris,

      Yes this is definitely possible.
      Change the following lines:

      Write-Host ” – “$list.Title
      if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value ” – $($list.Title)”}

      to

      Write-Host ” – “$list.Title “,”$list.ID
      if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value ” – $($list.Title), $($list.ID)”}

      Please let me know if this doesn’t work

      • What about the actual template ID of the list? The GUID is a great addition, but I need to find all lists in my farm that have are of a certain type, specifically those that were created by the Fab40 templates at some point.

      • Hi Scott,

        Thanks for your feedback.
        As I do not have any FAB40 lists, I can not tell you the exact syntax.

        However, you should be able to find an identifier for the FAB40 templates. Please use the following code to get some properties for a FAB40 library:

        $list = (get-spweb http://yoururl/site).Lists["FAB40List"]
        $list | fl Title, EntityTypeName, BaseType, BaseTemplate
        

        Tell me what that shows, I might be able to alter my script so you only get all FAB40 lists in your SharePoint farm.

        Kind regards,

        Nico

  1. Awesome script.

    Is there anyway to get only lists that have a minimum number of items in them? (show me every list that has over 10,000 items in them)
    Is there also a way to only show lists that have certain names in their title, e.g. show me all lists that sound like workflowhistory?

    Thanks a lot.

    • Hi Jim,

      Yes, this is definitely possible. It is all about how you query the data.
      Depending on how you would want your output, you could try something like this.

      1. Minimum number of items

      Add-PSSnapIn Microsoft.SharePoint.PowerShell
      Get-SPSite -Limit All | % {$urls += $_.Allwebs}
      
      foreach($url in $urls)
      {
      $web = Get-SPWeb $url.url
      $lists = $web.Lists
      foreach($list in $lists)
      {
      if($list.ItemCount -ge "10000"){
      Write-Host "SiteURL: $($web.url) `nList: $($list.Title)`n"
      }
      }
      }
      

      2. Get all lists that sound like workflowhistory

      Add-PSSnapIn Microsoft.SharePoint.PowerShell
      Get-SPSite -Limit All | % {$urls += $_.Allwebs}
      
      foreach($url in $urls)
      {
      $web = Get-SPWeb $url.url
      $lists = $web.Lists | ?{$_.title -like "Workflow*"}
      foreach($list in $lists)
      {
      Write-Host "SiteURL: $($web.url) `nList: $($list.Title)`n"
      }
      }
      

      Kind regards, Nico

  2. How about including the list’s ParentID so I can use this to import into my visio sitemap diagram? Would it be as simple as:
    Write-Host ” – “$list.Title “,”$list.ID “,”$listParentID
    if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value ” – $($list.Title), $($list.ID), $($list.ParentID)”}

    • Hi Eric,

      Thanks for taking your time to give some feedback. ParentID is not a property for a list object.
      I’m not sure what information you are trying to get, but you can use $list.ParentWeb or $list.ParentWebUrl

      Let me know if it works!

      Regards,

      Nico

      • Would love to, but I’m not an SP admin – and won’t be allowed to be one 😦

        Thanks, though, still a great article if I ever manage my own SP server(s)/server farm(s)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s