Recently, I was working on a SharePoint Online migration project, where we were required to get all lists and libraries from SharePoint Online sites. I used PnP PowerShell for this. In this tutorial, I will show you how to get all lists and libraries from a SharePoint Online site using PnP PowerShell.
Get All Lists and Libraries from a SharePoint Online Site using PnP PowerShell
To get all the lists and libraries of a SharePoint Online site using PnP PowerShell, you can use the Get-PnPList cmdlet. This command will return all the lists and libraries from the SharePoint site.
Below is the complete script. It will return the Title, URL, and Creation Date.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
$lists = Get-PnPList
foreach ($list in $lists) {
Write-Host "Name: $($list.Title)"
Write-Host "URL: $($list.RootFolder.ServerRelativeUrl)"
Write-Host "Created: $($list.Created)"
Write-Host "-----------------------------"
}I executed the above script, and you can see it returns all the lists and libraries from the SharePoint Online site.

The above examples did not show us if it is a list or a library. If you want to type, whether it is a list or a library, you can modify the PowerShell script like the one below.
Note: The template ID for the list is 100, and for the library, it is 101.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
# Retrieve all lists and libraries
$lists = Get-PnPList
# Function to determine type
function Get-ListType {
param (
[int]$baseTemplate
)
switch ($baseTemplate) {
101 { return "Library" }
100 { return "List" }
default { return "Other" }
}
}
# Display list details with type
foreach ($list in $lists) {
$listType = Get-ListType -baseTemplate $list.BaseTemplate
Write-Host "Name: $($list.Title)"
Write-Host "URL: $($list.RootFolder.ServerRelativeUrl)"
Write-Host "Type: $listType"
Write-Host "Created: $($list.Created)"
Write-Host "-----------------------------"
}You can also see the output in the screenshot below; it displays the type.

Check out Copy Items from One List to Another in SharePoint Online Using PnP PowerShell
Get All Lists in SharePoint Site using PnP PowerShell
Sometimes, you might required to get all the lists from the SharePoint site without the libraries. So, here is the PowerShell script to get all lists from a SharePoint site using PnP PowerShell.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
# Retrieve all lists and libraries
$lists = Get-PnPList
$allLists = @()
foreach ($list in $lists) {
if ($list.BaseTemplate -eq 100) {
$allLists += $list
}
}
# Display all lists
Write-Host "Lists:"
foreach ($list in $allLists) {
Write-Host "Name: $($list.Title)"
Write-Host "URL: $($list.RootFolder.ServerRelativeUrl)"
Write-Host "Created: $($list.Created)"
Write-Host "-----------------------------"
}I executed the above PnP PowerShell script, and you can see it displayed all the lists from my SharePoint site. You will also get the exact output.

Check out Recover a SharePoint Online Site Using PowerShell and PnP PowerShell
Get All Libraries from a SharePoint Online Site using PnP PowerShell
In this same way, let me show you how to get all the libraries from a SharePoint Online site using PnP PowerShell. This is also a very common requirement among PowerShell SharePoint developers.
Here is the complete script to get all the SharePoint document libraries using PnP PowerShell.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
# Retrieve all lists and libraries
$lists = Get-PnPList
$allLibraries = @()
foreach ($list in $lists) {
if ($list.BaseTemplate -eq 101) {
$allLibraries += $list
}
}
# Display all libraries
Write-Host "Libraries:"
foreach ($library in $allLibraries) {
Write-Host "Name: $($library.Title)"
Write-Host "URL: $($library.RootFolder.ServerRelativeUrl)"
Write-Host "Created: $($library.Created)"
Write-Host "-----------------------------"
}I executed the above PowerShell script, and you can see the output in the screenshot below.

Conclusion
In this tutorial, I have explained how to get all lists and libraries in SharePoint Online using PnP PowerShell. Also, I created two different scripts:
- Get all lists from a SharePoint Online site using PnP PowerShell
- Get all libraries from a SharePoint Online site using PnP PowerShell.
You may also like:
- Disable Versioning in a SharePoint Library Using PnP PowerShell
- Delete All Items from a SharePoint List using PnP PowerShell
- Add More Than 5000 Items to a SharePoint Online List using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.