Click here to Skip to main content
Click here to Skip to main content
Go to top

Update the "Created By" and "Modified By" Columns in SharePoint lists using PowerShell

, 21 Jan 2013
Rate this:
Please Sign up or sign in to vote.
Update the "Created By" and "Modified By" Columns in SharePoint lists using PowerShell.

Sometimes it is necessary to modify the 'Created By' field value for each list item and set it to the respective user's login ID. In my case it was required to Update "Created By" field value of Comments List of Blog Site. There was 1200+ comments in the list to modify.

The example simply replaced the created by field with user X to user Y. Apparently you also need to specify the user ID during replace Created by or Modified by.

// Add only if you use windows powershell. 
Add-PSSnapin Microsoft.SharePoint.Powershell

//Get a new object called $web to pick site
$web=get-SPWeb "You Web URL"

//Get a new object called $web to pick site
$list=$web.Lists["Your List"]

You can get the user ID of the user using the "EnsureUser()" method of "web" in PowerShell command.

$replacedUser =$web.EnsureUser("domainName\Account")

The code "$item["Author"] = $replacedUser " is used to updated the "Created By" column.

if you want to update the "Modified By" column, you have to add the code below:

"$item["Editor"] = $replacedUser "
foreach($item in $list.Items)       
{        
   $item["Author"] = $replacedUser   
   $item["Editor"] = $replacedUser   
   $item.update()        
}        
$web.Update()        
$web.dispose()

Don't forget to use $item.update() at the end, because otherwise your new value won't get displayed.

Reference:

http://sp-scripting.blogspot.com/2012/04/powershell-update-field-in-sharepoint.html

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

MJ Ferdous
Architect Brain Station-23
Bangladesh Bangladesh
Ferdous has industry level experience with SharePoint and has done several presentations and workshops on SharePoint. He also worked as SharePoint Consultant (CREDEM Italy, Robi etc) and Trainer (BASIS, JAXARA IT, LEADS Co.). He is currently working as SharePoint Architect at BrainStation-23. He also worked as Technical Project Manager for Congral LLC for managing revolutionizing Patient Centric Healthcare applications at the same company since 2009.
 
Before joining here, he worked for OT Group SPA and for Rockwell Automation in Italy. He worked on many international projects during his professional life. The major projects are included below:
Internal Enterprise Portal for Robi, Dhaka
nVision Solution for nSales A/S, Denmark
Shared Care Plan for Congral LLC, USA
Internet Banking Portal for the Bank of CREDEM, Italy
Document Management (DMS) for the Bank of CREDEM, Italy
MES solution for Rockwell Automation, Italy
Tourism for Travel Curve Inc., USA
and so on...
 
He is the author of several technical articles with over 49 articles published on http://mrbool.com where he is the Technical Author for the site and author of mssharepointtips.com as well. He is also founder of SharePoint Expert group.
 
Looking for a Offshore Development or partnership.............. in any development in Dot.Net & Sharepoint 2007,2010 Platform.
 
Search him in google by 'MJ Ferdous' to get all links, articles, profile etc
 
Contact him: ferdouscs@gmail.com mjferdous@live.com
 
Blog: http://geekswithblogs.net/ferdous
 
Specialties
===========
Production troubleshooting, maintainability and scalability
SharePoint 2007/2010
Dot.Net Application
Project Management
Document Management Solution
Follow on   Twitter

Comments and Discussions

 
QuestionDon't forget to item.Update() PinmemberLuisLobo7-Feb-13 22:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 21 Jan 2013
Article Copyright 2013 by MJ Ferdous
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid