Update List Item Using CSV File - PnP PowerShell - SharePoint 2013/2016/SPO

In this article, we are going to discuss updating a SharePoint List using .csv file using PnP PowerShell Module.

At one point in time, say you wanted to update a SharePoint List using the data from .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 that operation, like you could write a console application using SharePoint Server Object model in case of SharePoint 2013/2016 Environments, or you could write a console application using Client Side Object Model (JSOM/.NET Managed CSOM) in case of SP 2013/2016/SPO environments, or you could write a PowerShell script in case you have admin rights to the On-Premises farm or a PowerShell script for an SPO environment.

In this article, we are going to discuss 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.csv" data in such a way that it should be updated in the Target List. For example, the columns are all properly ordered etc…

Update List Item Using CSV File - PnP PowerShell - SharePoint 2013/2016/SPO 

Create a view in the Target list which matches with the .csv file. Once the view and .csv file are ready, run the updated PowerShell script created from the below sample script.

  1. #Connect to the Site Collection  
  2. Connect - PnPOnline– Urlhttp: //SiteCollectionURL–Credentials (Get-Credential)  
  3. #Import the column data from.csv file and store in a variable  
  4. Import - CsvD: \Data.csv | ForEach - Object {  
  5.     $Column1 = $_.Column1  
  6.     $Column2 = $_.Column2  
  7.     $Column3 = $_.Column3  
  8.     $Column4 = $_.Column4  
  9.     $Column5 = $_.Column5  
  10.     Write - Host$Column1$Column2$Column3$Column4$Column5  
  11.     $itemVal = @ {  
  12.         'Column1' = $Column1;  
  13.         'Column2' = $Column2;  
  14.         'Column3' = $Column3;  
  15.         'Column4' = $Column4;  
  16.         'Column5' = $Column5;  
  17.     }  
  18.     Set - PnPListItem - List 'CustomListName' - Identity$ID - Values$itemVal  
  19. }  

As a result, the list gets updated as expected.

Thanks.

Sharing is caring!!