Today I was working on a simple PowerShell script to update a Date/Time column in SharePoint 2010 – I simply needed to iterate through each list item; updating the value of a column to be today’s date.
As I was doing that, I thought “it sure would be nice if I could preserve the ‘modified by’ person while updating each of these list items.”
Well not only is this possible, but it’s almost too easy!
What I’m going to do using PowerShell is modify the “Title” of the second list item – the one created by me. However, I’m going to run this code on the server with the farm account.
The key piece is storing the value of the “Modified By” column into a variable so I can then put the value back into the column when I’m done.
Here is the simple PowerShell code to do this:
$web = Get-SPWeb http://siteurl $list = $web.lists["List Name"] $item = $list.items.getitembyid(2) $modifiedBy = $item["Editor"] #Editor is the internal name of the Modified By column $item["Title"] = "Modified in PowerShell" $item["Editor"] = $modifiedBy $item.Update() $list.Update() $web.Dispose()