In this PNP PowerShell tutorial, we will discuss how to check if a list exists in a SharePoint online site using PNP PowerShell. Also, we will see how to use get-pnplist in SharePoint.
Sometimes, you will get a requirement to check if a SharePoint online list exists on the site before creating a SharePoint list.
If you are new to PNP PowerShell then you can check ok the below article which explains how to install PNP PowerShell for SharePoint online and how to connect to SharePoint online sites using PNP PowerShell.
get-pnplist
get-pnplist is a PnP PowerShell cmdlets, that we can use to return all lists from a SharePoint Online site.
We can run the following command to get list with an name like below:
Get-PnPList -Identity Lists/TestList
Check if list exist in SharePoint Online site using PNP PowerShell
You can write, test and debug the PowerShell script using PowerShell ISE.
We can use the Get-PnPList cmdlet to get the list by title. GUID or by using a list URL.
Syntax:
Get-PnPList -Identity fb7f5261-c82d-449e-bf4b-b60438a58423
or
Get-PnPList -Identity Lists/Employees
or
Get-PnPList -Identity Employees
The PnP PowerShell cmdlet will work in SharePoint Online as well as on-premises versions like SharePoint 2019, SharePoint 2016, and SharePoint 2013.
Below is the full PnP PowerShell script:
$SiteUrl = "https://tsinfo.sharepoint.com/sites/SharePointSky/"
$ListName = "Employees"
Connect-PnPOnline –Url $SiteUrl
$list = Get-PnPList -Identity $ListName
If($list.Title -eq $ListName) {
Write-Host "List exist!"
}
else {
Write-Host "List does not exist!"
}
You can see the output like below:

If you will pass a list title which is not exists, it will display List does not exist message like below:

You may like following PnP PowerShell tutorials:
- Remove all items from a SharePoint Online list using PnP PowerShell
- PnP PowerShell Commands for SharePoint Online List
- PnP PowerShell commands for SharePoint Online Site
- The term ‘get-spweb’ is not recognized as the name of a cmdlet function PowerShell SharePoint error
- Connect-PnPOnline : The ‘Connect-PnPOnline’ command was found in the module ‘SharePointPnPPowerShellOnline’
- Save list as template in SharePoint Online using PowerShell
- How to create a communication site in SharePoint using PowerShell
- The term ‘Get-MsolUser’ is not recognized as the name of a cmdlet
I hope this tutorial helps to check if a list exists in SharePoint Online site using PNP PowerShell.
I am Bijay a Microsoft MVP (8 times –Â My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com