I am trying to programmatically update some metadata for a sharepoint item using powershell. Here is my code:
$web = getWebByURL("http://test-site/spadmin/")
$itm = $web.lists["Documents"].items[0]
$itm["Description"] = "This is a test edit"
$spfields = "Modified", "Created"
foreach($fieldname in $spfields){
$itm.parentList.Fields[$fieldname].ReadOnlyField = $false;
$itm.parentList.Fields[$fieldname].update()
$itm[$fieldname] = $sourceItm[$fieldname].toString()
$itm.parentList.Fields[$fieldname].ReadOnlyField = $true;
$itm.parentList.Fields[$fieldname].update()
}
$itm["Author"] = $sourceItm["Author"].toString()
$itm["Editor"] = $sourceItm["Editor"].toString()
$itm.updateOverwriteVersions()
# Also tried $itm.update()
# Also tried $itm.systemUpdate()
Error:
Exception calling "SystemUpdate" with "0" argument(s): "The file Documents/1test.doc has
been modified by Domain\myusername on <date time stamp>."
I have tried to re get a handle on the item using
$itm = $itm.parentList.getItemById($itm.id)
I have tried to enable/disable unsafeupdates
$itm.parentList.parentWeb.AllowUnsafeUpdates = $true
Am I missing something here or going about this the wrong way? Please help!!