September 21, 2013

Update Modified by and Created by in SharePoint using Powershell


Many times you have to update list with large number of items or some time we have to change Modified or created by names of all items, yeah we are aware about System.Update() method but if data has populated and no code action will take place and requirement says to update because we don't wants to confuse client and his customers so in very rare and after approval we execute it to update modified and created by names.

We can use below script to update thousands of list items in single shot. but take care once changes are done by PowerShell can not be roll back.

so to update sharepoint list items simply can save below Powershell script in a .PS1 file and run it with Elevated privileges in SharePoint server where you has permission to modify items.

PowerShell Code:
<# Created by : Praveen Pandit
   Purpose  : To update Modified and created by Names.
   Created Date : June, 2011
#>
     $targetUser=$oWeb.EnsureUser("domain\userid");  
     # in List Created by -Author and Modifed by -Editor
     $oItem["Author"] = $targetUser            
     $oItem["Editor"] = $targetUser  
     # You can add other fields here any field value data time etc....
     $oItem.Update()  
 



Please share any issue or findings on this.


--
Regards,
Praveen Pandit

No comments:

Post a Comment