0
我需要的是使用Powershell SharePoint.Client更新每個第二個項目。 我用這裏的一些代碼http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/15/using-powershell-to-get-data-from-a-sharepoint-2010-list.aspx 並添加了所需的功能。我在Powershell中很新,所以我可能犯了一些愚蠢的錯誤。你會檢查我的代碼,並指出那個錯誤。SharePoint 2010使用Powershell SP.Client更新每個Socond列表項目
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
}
在此先感謝您。