Update And Delete SharePoint List Items Using PnP PowerShell

In this blog, we are going to see how to update and delete SharePoint list items using PnP PowerShell. PnP Provisioning is a community-driven platform that enables fast development of components that define your application infrastructure & the contents to some extent. We use CSOM and can work against both SharePoint Online and SharePoint On-Premises.

Prerequisite

Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands.

Connect to Site

Connect to SharePoint site using Connect-PnPOnline cmdlet. The required parameters are,

  • Url
    The SharePoint site URL (Eg: https://hubflysoft.sharepoint.com/sites/Hubfly)

The following code snippet helps to connect SharePoint sites.

  1. $siteurl="https://<tenant-name>.sharepoint.com"  
  2. Connect-PnPOnline -Url $siteurl  

 

SharePoint

To Update a SharePoint List Item

The following code snippet helps to update SharePoint List item. The list Item can be updated by “Set-PnPListItem” on the SharePoint site. It applies to SharePoint Server 2013, SharePoint Server 2016, and SharePoint Online.

The required parameters are,

  • Identity
    The ID of the list item, or actual list item object

  • List
    The ID, Title, or Url of the list

  • Values
    Use the internal names of the fields when specifying field names.

    • Single line of text: -Values @{"Title" = "Title New"}

    • Multiple lines of text: -Values @{"MultiText" = "New text\n\More text"}

    • Rich text: -Values @{"MultiText" = "<strong>New</strong> text"}

    • Choice: -Values @{"Choice" = "Value 1"}

    • Number: -Values @{"Number" = "10"}

The optional parameters are,

  • ContentType
    Specify either the name, ID, or an actual Content type

  • SystemUpdate
    Update the item without creating a new version (Only applicable to SharePoint Online)

The following code snippet helps to update SharePoint List item.

Set-PnPListItem -List HubflyTeam -Identity 3 -Values @{"NameHF" = "Arut"}

SharePoint

 

To Delete a List Item,

The list items can be deleted by “Remove-PnPListItem” cmdlet on the SharePoint site. It applies to SharePoint Server 2013, SharePoint Server 2016, SharePoint Online.

The required parameters are,

  • Identity
    The ID of the list item, or actual ListItem object

  • List
    The ID, Title, or URL of the list

The optional parameters are,

  • Force
    Specifying the Force parameter will skip the confirmation question.

The following code snippet helps to update SharePoint List item.

Remove-PnPListItem -List HubflyTeam -Identity 3

SharePoint

 

Thus, you have learned how to update and delete list items programmatically SharePoint site. PnP PowerShell is supported by SharePoint Online. The operations mentioned above are tested on SharePoint Online environments. Feel free to fill up the comment box below, if you need any assistance.