0

Hi all,

i have a sharepoint 2010 site with blog, blog contains few posts with comments. I need to modify comment property via powershel.

Have used the following code:

$spWeb = Get-SPWeb http://portal/strategy  \\get the site
$dd = $spWeb.Lists["Comments"]  \\get the list of all comments
$dd.Items[1] \\ here i select required comment

Now i can see it's properties like

Xml:

<z:row xmlns:z='#RowsetSchema' ows_ID='19' ows_ContentTypeId='0x0111008F1E084351F                                         D240821BA37C4537E336' ows_ContentType='Comment'  ows_Title='test' ows_Modified=
'2012-09-28 14:42:25' ows_Created='2012-09-28 14:29:53' ows_Author='1;#spsadmin' ... />

So the problem is so i can't modify that ows property, like ows_Created or ows_Modified via powershell.

Thanks.

6
  • Why must you use XML, why not $dd.GetItemById(1)["Created"] = Date – eirikb Sep 28 '12 at 14:56
  • Because PS returns error which i couldn't understand: PS C:\Users\spsadmin> $dd.GetItemById(19)["Created"] = 2012-09-27 **Unable to index into an object of type** Microsoft.SharePoint.SPListItem. At line:1 char:21 + $dd.GetItemById(19)[ <<<< "Created"] = 2012-09-27 + CategoryInfo : InvalidOperation: (Created:String) [], RuntimeException + FullyQualifiedErrorId : CannotIndex – Sergey Sep 28 '12 at 16:12
  • looks like the required item doesn't have this property, because all similar are included into Xml which is shown above. – Sergey Sep 28 '12 at 16:19
  • Try using Date as I did in my example, does it work? – eirikb Sep 28 '12 at 18:49
  • sad but not working – Sergey Sep 28 '12 at 19:09
1
  1. As far as I know, Created and Modified fields are read only fields on SharePoint, so even if you're accessing in the right way, you wont be able to update their values.
  2. By all means, avoid using web.Lists["ListName"]. Instead use web.Lists.TryGetList("ListName"). Your app/script performance will improve
0

All of the ows_ prefixes are added to the XML due to backwards compatablity with the xml used when SharePoint as called "Office Web Server", but are not part of the field names.

You can update the comment with powershell like this:

$i = $dd.GetItemById(19)
$i["Created"] = Get-Date "2012-09-27"
$i.Update()
0
0

You can change system properties like Created, Created By, Modified and Modified By as well:

$dd = $spWeb.Lists["Comments"]
$item = $dd.Items[1] 
$item[[Microsoft.SharePoint.SPBuiltInFieldId]::Author] = "1;#Edward Wilde"
$item[[Microsoft.SharePoint.SPBuiltInFieldId]::Editor] = "1;#Edward Wilde"
$item.UpdateOverwriteVersion()

See these references:

https://blogs.edwardwilde.com/2010/04/21/how-do-you-update-the-author-or-created-by-and-editor-or-modified-by-last-modified-fields-of-a-list-item-splistitem/

https://pholpar.wordpress.com/2009/10/10/changing-system-properties-for-an-item-from-the-sharepoint-user-interface-part-1/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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