I am working on an Issue tracking list inside SharePoint team site and i need to modify the "Editor" & "Modified" fields for an existing item's version comment:-

enter image description here

so i wrote the following power-shell script, to get the first comment of an item and update its fields (Editor & Modified fields):-

#set the web url and the list name to work upon
$url = "http://***/Customer Sites/customerA/"
$listName = "Action"
$fileName = "12312312"

#Get the appropriate list from the web
$web = get-SPWeb $url
$list = $web.lists[$listName]

#Get the file using the filename
$item = $list.Items | ? {$_.Title -eq $fileName}
$versions = $item.versions 
$version = $versions[0];


#Set the created by values
$userLogin = "a***\m***"
$dateToStore = Get-Date "10/03/2015 10:15:20"
$dateToStore2 = Get-Date "12/03/2015 23:15:20"

$user = Get-SPUser -Web $web | ? {$_.userlogin -eq $userLogin}
$userString = "{0};#{1}" -f $user.ID, $user.UserLogin.Tostring()


#Sets the created by field


#Set the modified by values
$version["Editor"] = $userString
$version["Modified"] = $dateToStore2


#Store changes without overwriting the existing Modified details.
$item.UpdateOverwriteVersion()

but i got the following exception on $version["Editor"] = $userString & $version["Modified"] = $dateToStore2 statments:-

Unable to index into an object of type Microsoft.SharePoint.SPListItemVersion.

here is a screenshot of my power-shell window with the exception that i got:-

enter image description here

so can anyone advice how i can edit these 2 fields for an item comment ?

You can get the field value of a field in a particular item version using $version.item["Field Display name"] but I think it is a read only property and you cant set it via code.

https://msdn.microsoft.com/EN-US/library/office/microsoft.sharepoint.splistitemversion_members.aspx

  • Yes seems i can not update them as they are read-only, so is there a way to create new version for an item using powershell and pass these info to it ; created date, create by + comment text ? i need this as i am merging multiple lists inside one list, and to do so i need to preserve the original item versions info, so i want to create these versions on the new list to match the old list info ? – john Gu Nov 27 '15 at 12:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.