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:
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 from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com