How to check if a list exists in SharePoint Online site using PNP PowerShell

In this PNP PowerShell tutorial, we will discuss how to check if a list exists in a SharePoint online site using PNP PowerShell.

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.

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:

check if a list exists in SharePoint Online site using PNP PowerShell

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

check if a list exists in SharePoint site using PNP PowerShell

You may like following PnP PowerShell tutorials:

I hope this tutorial helps to check if a list exists in SharePoint Online site using PNP PowerShell.

>