Tuesday, May 6, 2014

PowerShell: Update a column value for a subset of documents in a document library using a CSV file

I recently had the need to update the column value for a subset of documents in a document library. I was given a CSV file with the Title of each file that needed the updated value. The column in the document library that needed updating was named DeleteFlag.

After some googling, I came across the following blog post that would serve as the basis for my solution. Once again, PowerShell to the rescue!

http://technology-23.blogspot.com/2012/08/update-sharepoint-library-from-csv.html#!/2012/08/update-sharepoint-library-from-csv.html

Here are the steps to my solution.

1) Add another column in the CSV file to match the column you want to update in the SharePoint library. As indicated above, the column name for me was DeleteFlag. Be sure to also add the value(s) as needed for the new column. In my case, I had a single value for all items. Copy the file to the SharePoint sever where you will run the PowerShell script.

2) Create a new .ps1 file (using Notepad) and copy/paste the following.

Change the $url, $data, and $list variables to reflect your environment. As you can see, the script matches the Title in the CSV file with the Title in the document library, and then updates the DeleteFlag column for each item in the document library with the value in the DeleteFlag column for the matching items in the CSV file.

3) Copy the .ps1 file to the same SharePoint server where you saved the CSV file.

4) Run the .ps1 file and site back and watch the magic happen!

No comments:

Post a Comment