PnP PowerShell Commands for SharePoint Online List

In this PowerShell tutorial, We will see how to use PnP PowerShell commands to work with SharePoint Online Lists. We will see below examples:

  • Create a SharePoint Online List using PnP PowerShell
  • Check if the SharePoint Online List exists or not using PnP PowerShell
  • Remove SharePoint Online List using PnP PowerShell
  • Remove SharePoint Online List with Force
  • Remove SharePoint Online List with Recycle bin
  • Retrieve SharePoint Online List using PnP PowerShell
  • Update SharePoint Online List Title Using PnP PowerShell

All these PowerShell commands you can run in Windows PowerShell ISE.

If you are new to PnP PowerShell, then you can follow the below article on Getting Started with PnP PowerShell in SharePoint.

Create a SharePoint Online List using PnP PowerShell:

Now, we will see how to create a SharePoint Online List using PnP PowerShell. Below represents the PowerShell command:

$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"

New-PnPList -Title $listName -Url "TSInfoTeam" -Template GenericList
Write-Host ("SharePoint List is created")
Create SharePoint Online List using PnP PowerShell

When you run the above PnP PowerShell command, then you can see the SharePoint Online list will create which is available in the Site Content of the SharePoint Online Site.

Create a SharePoint Online List using PnP PowerShell

Check if the SharePoint Online List exists or not using PnP PowerShell:

If you want to check if the SharePoint Online List exists in your SharePoint Site or not, then follow the below PnP PowerShell command:

$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"
if($listName)  
        {  
           write-Host  ("SharePoint List is already exists")   
        }  
        else 
        {
            Connect-PnPOnline -Url $siteurl -Credentials $cred            
            New-PnPList -Title $listName -Url "TSInfoTeam" -Template GenericList
            Write-Host ("SharePoint List is created")
        }

Once you will run the command, then it will let you know if the SharePoint exists or not.

Check if SharePoint Online List exists or not using PnP PowerShell

Remove SharePoint Online List using PnP PowerShell:

We can easily remove a SharePoint Online list from SharePoint site collection using the PnP PowerShell command.

$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"

Remove-PnPList -Identity $listName
Write-Host ("SharePoint List is Removed")

Once you will run the above command, then it will ask you to ensure to delete the SharePoint list as shown below.

Remove SharePoint Online List using PnP PowerShell

When you will click on Yes, then the SharePoint Online List will remove.

Remove a SharePoint Online List using PnP PowerShell

Remove SharePoint Online List with Force:

Similarly, if you will run the below PnP PowerShell command, then the SharePoint list will remove forcefully without asking the confirmation.

Remove-PnPList -Identity $listName -Force
Remove SharePoint Online Lists using PnP PowerShell

Remove SharePoint Online List with Recycle bin:

When you will run the below PnP PowerShell command, then it will ask you to ensure to delete the SharePoint Online List.

Remove-PnPList -Identity $listName -Recycle
Remove SharePoint List using PnP PowerShell

Once you clicked on Yes button, then the SharePoint Online List will remove and it will move to the Recycle bin as like the below screenshot.

Remove SharePoint Lists using PnP PowerShell

Retrieve a SharePoint Online List using PnP PowerShell:

Below is the PnP PowerShell command to retrieve the SharePoint Online List from your SharePoint Online Site.

$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred

Get-PnPList -Identity 486ee331-e38f-4d89-82cf-8e0bef45d853
Write-Host ('SharePoint List is Retrieved with Id')
Get-PnPList -Identity Lists/TSInfoTeam
Write-Host ('SharePoint List is Retrieved with URL')

When you will run the command, then you will get your SharePoint Online List with List Title, Id and Url as shown below.

Retrieve SharePoint Online List using PnP PowerShell

Update SharePoint Online List Title Using PnP PowerShell:

Suppose you want to update your SharePoint Online List Title with a new title name, then you can do it by using PnP PowerShell command.

Here in the below screenshot, my SharePoint List Title is TSInfoTeam. I want to update this List Title as TSInfoGroup.

Update SharePoint List Title Using PnP PowerShell

Follow this below PnP PowerShell command to update the SharePoint Online List Title.

$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"

Set-PnPList -Identity $listName -Title 'TSInfoGroup' -Description 'This SharePoint List is used for TSInfo'
Write-Host ('SharePoint List title is updated')
Update SharePoint Online List Title Using PnP PowerShell

Once the above command will run and finish, go to that SharePoint Online List and just refresh that page. Then you can see the title has been updated as shown in the below screenshot.

Update SharePoint Online Lists Title Using PnP PowerShell

As I have also updated the SharePoint Online List Description, you can see the updated description in the List Settings page as like below.

Update SharePoint Online Lists Title Using PnP PowerShell code

Also, you may like the below PowerShell tutorials:

Hence in this PowerShell tutorial, We learned how to work with SharePoint online list with PnP PowerShell cmdlets. We saw the below examples:

  • Create a SharePoint Online List using PnP PowerShell
  • Check if the SharePoint Online List exists or not using PnP PowerShell
  • Remove SharePoint Online List using PnP PowerShell
  • Remove SharePoint Online List with Force
  • Remove SharePoint Online List with Recycle bin
  • Retrieve SharePoint Online List using PnP PowerShell
  • Update SharePoint Online List Title Using PnP PowerShell
>