我需要的是使用 Powershell SharePoint.Client更新每个Second项目。我在这里使用了一些代码http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/15/using-powershell-to-get-data-from-a-sharepoint-2010-list.aspx 和添加了所需的功能。我在 Powershell 中很新,所以我可能犯了一些愚蠢的错误。请您检查我的代码并指出那个错误。
Add-Type -path C:\Microsoft.SharePoint.Client.dll
Add-Type -path C:\Microsoft.SharePoint.Client.Runtime.dll
Function Get-SPClientList {
$cSharp = @"
using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;
namespace SPClient
{
public class SharePointList
{
public static ListItemCollection GetList()
{
ClientContext clientContext = new ClientContext("http://sp10sl1:55555/mychuldesite");
List list = clientContext.Web.Lists.GetByTitle("CustomList");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(list);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
return listItems;
}
}
}
"@
$assemblies = @(
"$PSSCriptRoot\Microsoft.SharePoint.Client.dll",
"$PSSCriptRoot\Microsoft.SharePoint.Client.Runtime.dll"
"System.Core"
)
Add-Type -TypeDefinition $cSharp -ReferencedAssemblies $assemblies
$items = [SPClient.SharepointList]::GetList()
$out = @()
$i=0
foreach ($item in $items)
{
if($i % 2 -eq 0)
{
$item["Title"] = "ClientTitle";
$item["UserData"] = "ClientData";
$item.Update();
}
$i += 1
}
$out
}
先感谢您。