使用ListData.svc和PowerShell更新SharePoint列表项

使用ListData.svc和PowerShell更新SharePoint列表项,powershell,sharepoint,sharepoint-2010,odata,powershell-3.0,Powershell,Sharepoint,Sharepoint 2010,Odata,Powershell 3.0,是否有一种方法可以使用PowerShell更新SharePoint 2010列表条目,而不使用SharePoint客户端?如果是,怎么做 要获得所需字段,我将: $url = 'http://myserver/resource/_vti_bin/ListData.svc/TheList(1234)?$select=Id,Title,StartingDate,Hours' $webRequest = Invoke-WebRequest -Uri $url -Method Get -UseDefa

是否有一种方法可以使用PowerShell更新SharePoint 2010列表条目,而不使用SharePoint客户端?如果是,怎么做

要获得所需字段,我将:

$url = 'http://myserver/resource/_vti_bin/ListData.svc/TheList(1234)?$select=Id,Title,StartingDate,Hours'

$webRequest = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials
[xml]$xml = $webRequest.Content

$properties = $xml.feed.entry.content.properties
$properties | Format-Table -Property Id,Title,StartingDate,EndingDate,Hours

我想修改
EndingDate
Hours
字段。

以下示例演示了如何使用更新列表项:


作为替代方案,您也可以使用,而不是,例如:

Invoke-RestMethod -Uri $EndpointUrl -Method Post -UseDefaultCredentials -Headers $headers -ContentType "application/json" -Body $ItemPayload

为什么选择Invoke RestMethod而不是Invoke WebRequest?有没有办法通过在散列中设置公式来增加字段的值?类似于
@{Hours=Hours+0.25}
?您是否考虑过将此PowerShell功能(以及剩余的CRUD操作)打包到单个PowerShell模块中,就像您对repo所做的那样?这是一个很好的问题:)考虑过这一点,因为它只涵盖了APII的一小部分,这将有助于项目。
#Update Task list item
$ItemProperties = @{  
       Title = "Approval Task"; 
       StartDate = "2014-04-24T00:00:00"}
Update-ListItem -WebUrl "http://contoso.intranet.com" -ListName "Tasks" -ItemId 1 -Properties $ItemProperties
Invoke-RestMethod -Uri $EndpointUrl -Method Post -UseDefaultCredentials -Headers $headers -ContentType "application/json" -Body $ItemPayload