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.
- 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.
- $cred = Get - Credential
- $siteurl = "https://snips.sharepoint.com/sites/dev"
- $listTitle = "Documents 1"
- Connect - PnPOnline - Url $siteurl - Credential $cred
- $list = Get - PnPList - Identity $listTitle
- If($list.Title - eq $listTitle) {
- Write - Host $listTitle " - List exist!"
- }
- ELSE {
- Write - Host $listTitle " - List not exist!"
- }
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.