This PowerShell SharePoint tutorial explains, how we can retrieve all lists names and all lists guids from SharePoint online site using PowerShell. We will also see how to retrieve all lists and libraries from the SharePoint 2013/2016 web application using PowerShell.
In my SharePoint online site, I have few lists and document libraries and by using PowerShell I want to retrieve all the lists and libraries. We can easily get list name and guid SharePoint PowerShell.
We will also discuss how we can download all the lists and libraries in CSV format.
You can run, debug, and test the PowerShell using Visual studio code or by using Windows PowerShell ISE. Check out an article on the advantages of using Windows PowerShell ISE and also check how an article on how to debug PowerShell in Visual studio code.
PowerShell Script to Retrieve All List names and GUID:
You need to provide the SharePoint online site url, username and password to connect to SharePoint online site.
Try{
Add-Type -Path 'C:\Users\Bijaya.Sahoo\Desktop\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Users\Bijaya.Sahoo\Desktop\Microsoft.SharePoint.Client.Runtime.dll'
}
catch {
}
$siteUrl = "https://onlysharepoint2013.sharepoint.com/sites/Bhawana/"
$username = "bijay@onlysharepoint2013.onmicrosoft.com"
$password=ConvertTo-SecureString "********" -AsPlainText -Force
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials
$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()
$lists| select -Property Title, ID
You can run the above script using Microsoft Windows PowerShell ISE. Once you run you can see the output like below:

PowerShell Script to Retrieve All List names and GUID with export to .csv format
We can use export-csv cmdlet to download the result in .csv format. You can use Windows PowerShell ISE or Visual studio code to run, debug and test the below PowerShell script.
Try{
Add-Type -Path 'C:\Users\Bijaya.Sahoo\Desktop\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Users\Bijaya.Sahoo\Desktop\Microsoft.SharePoint.Client.Runtime.dll'
}
catch {
}
$siteUrl = "https://onlysharepoint2013.sharepoint.com/sites/Bhawana/"
$username = "bijay@onlysharepoint2013.onmicrosoft.com"
$password=ConvertTo-SecureString "*******" -AsPlainText -Force
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials
$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()
$lists| select -Property Title, ID | export-csv -Path C:\Users\Bijaya.Sahoo\Desktop\Bijay\lists.csv -NoTypeInformation
Once you run above script, the result will be downloaded in .csv format in the provided path.
Morgan Tech Space wrote a beautiful article on how to retrieve all lists and libraries from a web application in SharePoint 2013/2016.
If you are new to PowerShell SharePoint, read an article on Working with PowerShell in SharePoint Online/2016/2013.
Get All Lists from a web application using PowerShell in SharePoint 2013/2016
Below is the PowerShell Script to get all lists from a web application in SharePoint 2013/2016. It will export all the lists from the web application (all site collections & subsites) in a CSV file.
Add-PSSnapin Microsoft.SharePoint.PowerShell
$SPWebApp = Get-SPWebApplication “http://WebApplicationURL/” -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 “E:\\All-Lists.csv” -NoTypeInformation -Encoding UTF8
The above PowerShell script, you can run using visual studio code or Windows PowerShell ISE.
Get All Document Libraries from a web application using PowerShell in SharePoint
Below is the PowerShell script which will retrieve all the document libraries from a web application in SharePoint 2013/2016. It will export all the document libraries from the web application (all site collections & subsites) in a CSV file.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$SPWebApp = Get-SPWebApplication “http://WebApplicationURL/”
# 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 “E:\\All-Libraries.csv” -NoTypeInformation -Encoding UTF8
References: https://www.morgantechspace.com/2016/03/get-all-lists-in-sharepoint-using-powershell.html
You may like following PowerShell SharePoint tutorials:
- 15 PowerShell Basic Commands Examples
- Retrieve SharePoint online Current Site Title & URL, Parent Web Title & URL, Root Web Title & URL using PowerShell
- Working with PowerShell Variables
- Top 51 PowerShell Examples You Should Learn
- SharePoint 2016 PowerShell Script to list all Users in Site Collection
- SharePoint 2013 backup and restore using PowerShell
- PowerShell find files modified in last N days
- Insert/Add item to SharePoint Online list using PowerShell
Tags: get all lists in sharepoint site powershell, get all sharepoint lists by using powershell, powershell script to get all sharepoint lists, sharepoint 2010 powershell get all lists in a site collection, get list name and guid sharepoint powershell, sharepoint powershell get all lists, export sharepoint list to csv using powershell
Hope this article will be helpful to get all lists and libraries from SharePoint Online site collection using PowerShell.
We also saw how to retrieve all lists and libraries from SharePoint 2013/2016 using PowerShell.
Hello Everyone!! I am Bhawana a SharePoint MVP and having about 10+ years of SharePoint experience as well as in .Net technologies. I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools. Now exploring more in SharePoint 2016 🙂 Hope here I can contribute and share my knowledge to the fullest. As I believe “There is no wealth like knowledge and no poverty like ignorance”