At some point in time, you may want to update a SharePoint List using the data from a .CSV file which sits in a web application of any one of the SharePoint environments (SharePoint 2013/2016/SPO). Of course, we do have a lot of options to perform this task, like the following -
In this article, we are going to discuss the process of updating a SharePoint List using PnP PowerShell Module. To get to know more about the PnP PowerShell, click here.
Let’s get started with the steps in brief.
Prepare the .csv file data in such a way that it should be updated in the target list, i.e., the columns should all be properly ordered.
Create a View in the target list which matches with the .csv file.
Once the View and the .csv file are ready, run the updated PowerShell script created from the below sample script.
- #Connect to the Site Collection
- Connect-PnPOnline –Url http://SiteCollectionURL –Credentials (Get-Credential)
- #Import the column data from .csv file and store in a variable
- Import-Csv D:\Data.csv |
- ForEach-Object {
- $Column1 = $_. Column1
- $Column2 = $_. Column2
- $Column3 = $_. Column3
- $Column4 = $_. Column4
- $Column5 = $_. Column5
- Write-Host $ Column1 $ Column2 $ Column3 $ Column4 $ Column5
- $itemVal = @{
- 'Column1' = $Column1;
- 'Column2' = $Column2;
- 'Column3' = $Column3;
- 'Column4' = $Column4;
- 'Column5' = $Column5;
- }
- Set-PnPListItem -List 'CustomListName' -Identity $ID -Values $itemVal
- }
As a result, the list gets updated as expected.
Thanks.
Sharing is caring!!

Join the conversation! Your thoughts help the community grow.