Summary: This post describes how to get 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:directoryfilename.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:
This is excellent post explaining your last article related to the retrieval of workflows.
Excellent – Thank you. Is there a way to get the list ID’s for each list also?
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:
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
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
2. Get all lists that sound like workflowhistory
Kind regards, Nico
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
Thank you for this! This saved me from having to work the weekend to inventory our lists.
Glad to hear it helped you 🙂 have a good weekend!
You have to an SP admin, and run this on the SP server, correct?
Hi Chris,
Yes this is correct. Make sure to start the “SharePoint Management Shell”.
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)
Here is one for you :O)
is there any way to get only the lists created by user, or skip all OOTB, system related lists ?
Thx
Petr
Is there to get way to copy the first 5000 items from a list to another list order by date?
Tks.
Cristian
Hi,
Is there any way to filter all list contains more than 3500 in a sharepoint farm?
By
Mani
Excellent script, works very well
Thank you!