Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
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
show 1 more comment

2 Answers

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()
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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