Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint

Update the Created By and Modified By Columns in SharePoint Lists using PowerShell

0.00/5 (No votes)
21 Jan 2013CPOL 50K  
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 were 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.

PowerShell
// 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.

PowerShell
$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:

PowerShell
"$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

License

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