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:-
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:-
so can anyone advice how i can edit these 2 fields for an item comment ?