Check If The List Is Present In The SharePoint Site, Using PnP PowerShell

In this blog, we are going to see how to check if the given list is available in the current context site or not. The PnP PowerShell cmdlet is used to get the list based on the title or id.
  1. Get-PnPList -Identity <List Title or ID or Url>  
The below PowerShell code helps to check if the given list is present or not based on the List Title using PnP PowerShell.
  1. $cred = Get - Credential  
  2. $siteurl = "https://snips.sharepoint.com/sites/dev"  
  3. $listTitle = "Documents 1"  
  4. Connect - PnPOnline - Url $siteurl - Credential $cred  
  5. $list = Get - PnPList - Identity $listTitle  
  6. If($list.Title - eq $listTitle) {  
  7.     Write - Host $listTitle " - List exist!"  
  8. }  
  9. ELSE {  
  10.     Write - Host $listTitle " - List not exist!"  
  11. }  
Output

If the list not present on the site -

Documents 1 - List not exist!

If the list is present on the site -

Documents 1 - List exist!

Use the https://github.com/SharePoint/PnP-PowerShell link to get and install the PnP PowerShell module and try the above code.
Ebook Download
View all
Learn
View all