Geeks With Blogs

News invisible hit counter View My Stats
Technical Speaking

 

Sometime, 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

Posted on Wednesday, November 7, 2012 6:52 PM | Back to top


Comments on this post: Update the “Created By” and “Modified By” Columns in SharePoint lists using PowerShell"?

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © MJ Ferdous | Powered by: GeeksWithBlogs.net