Create, Read, Update, and Delete an Item from a SharePoint Online List using PnP PowerShell

In this tutorial, I will show you how to create, read, update, and delete an item from a SharePoint Online list using PnP PowerShell.

This is a complete CRUD (Create, Read, Update, Delete) operation in SharePoint list items using PnP PowerShell.

For all the examples, I will use the below SharePoint list named “ProjectTasks” with the following columns:

  • Title (Single line of text)
  • Description (Multiple lines of text)
  • DueDate (Date and Time)
  • AssignedTo (Person or Group)

You can create this SharePoint list on your SharePoint Online site before using the examples below. You can also create the SharePoint list using PnP PowerShell.

I have created the above list, and with sample data, you can see the SharePoint Online list looks like below:

powershell sharepoint crud operations

Create an Item in a SharePoint List using PnP PowerShell

Let me first show you how to create an item in a SharePoint Online list using PnP PowerShell.

To insert an item to a SharePoint Online list, you can use the Add-PnPListItem cmdlet. Below is the syntax.

Add-PnPListItem [-List] <ListPipeBind> [-ContentType <ContentTypePipeBind>] [-Values <Hashtable>]
 [-Folder <String>] [-Label <String>] [-Connection <PnPConnection>] 

Here is the complete PowerShell script to add an item to a SharePoint Online list. I have used the above SharePoint list.

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/MarketingTeam" -Interactive

# Add a new item to the ProjectTasks list
Add-PnPListItem -List "ProjectTasks" -Values @{
    Title = "Design Phase";
    Description = "Complete the design phase of the project";
    DueDate = "2025-08-01";
    AssignedTo = "henriettam@szg52.onmicrosoft.com"
}

Once you execute the above script and open the SharePoint Online list, you will see that the above item has been added to the list. Look at the screenshot below:

add new item to sharepoint list using powershell

Read Delete All Items from a SharePoint List using PnP PowerShell

Get All SharePoint List items using PnP PowerShell

Now, let me show you how to read all SharePoint list items using PnP PowerShell.

To get SharePoint list items using PnP PowerShell, you can use the Get-PnPListItem cmdlet.

Here is the complete PowerShell script to read items from the “ProjectTasks” list using the Get-PnPListItem cmdlet.

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/MarketingTeam" -Interactive

# Retrieve all items from the ProjectTasks list
$items = Get-PnPListItem -List "ProjectTasks"
foreach ($item in $items) {
    Write-Host "Title: $($item['Title']), Description: $($item['Description']), DueDate: $($item['DueDate']), AssignedTo: $($item['AssignedTo'])"
}

Once you execute the above PowerShell script, you can see the output in the screenshot below; it gets all the items from the SharePoint list.

get sharepoint list items using pnp powershell

Update a SharePoint List item using PnP PowerShell

Now, let me show you how to update a SharePoint list item using PnP PowerShell.

To update an item in the “ProjectTasks” list, you need the ID of the item you want to update. You can then use the Set-PnPListItem cmdlet.

Here is an example where I provide item ID 2 to update the SharePoint list item.

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/MarketingTeam" -Interactive

# Update an item in the ProjectTasks list
Set-PnPListItem -List "ProjectTasks" -Identity 2 -Values @{
    Title = "Design Phase Updated";
    Description = "Update the design phase of the project";
    DueDate = "2025-08-15";
    AssignedTo = "johannal@szg52.onmicrosoft.com"
}

After I executed the above PowerShell script using VS code, the item got updated, as shown in the screenshot below.

update sharepoint list item using pnp powershell

This is how to update a SharePoint list item using PnP PowerShell.

Read Add More Than 5000 Items to a SharePoint Online List using PnP PowerShell?

Delete SharePoint List Item using PnP PowerShell

Now. let me show you how to delete a SharePoint list item using PnP PowerShell.

In PnP PowerShell, you can use the Remove-PnPListItem cmdlet to delete an item from the SharePoint list/

Here is the complete PowerShell script to delete an item from the “ProjectTasks” list using the Remove-PnPListItem cmdlet.

In the below example, you can see I passed the item ID as 2 and the script will delete the item whose ID is equal to 2.

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/MarketingTeam" -Interactive

# Delete an item from the ProjectTasks list
Remove-PnPListItem -List "ProjectTasks" -Identity 2 -Force

Once you execute the above PowerShell script, the item whose ID=2 will be deleted from the SharePoint Online list.

This is how to delete an item from a SharePoint list using PnP PowerShell.

Conclusion

In this tutorial, I have explained a CRUD operation on SharePoint list items using PnP PowerShell. With various examples, I have explained the following things:

  • Create list item in SharePoint using PnP PowerShell
  • Get SharePoint list items using PnP PowerShell
  • Update a list item using PnP PowerShell in SharePoint Online
  • How to delete a list item using PnP PowerShell

You may also like the following tutorials:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.