0

我需要的是使用 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
}

先感谢您。

4

1 回答 1

0

好的,我已经设法解决了。我们可以简单地在 C# 块内添加更新逻辑,然后调用这个函数。

它应该看起来像这样

Add-Type -path C:\Microsoft.SharePoint.Client.dll
Add-Type -path C:\Microsoft.SharePoint.Client.Runtime.dll



$cSharp = @"


using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
namespace SPClient
{
public class SharePointList
{
public static ListItemCollection GetList()
{
ClientContext clientContext = new ClientContext ("http://*****:****/*****");
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();
int i=0;
foreach ( ListItem item in listItems)
{
 if(i % 2 == 0)
  {
item["Title"] = "This is client Powershell";
item["UserData"] = "Yeap it is";
item.Update();
clientContext.ExecuteQuery();
}
i++;
}

return listItems;
}
}
}
"@

$assemblies = @( 
    "$PSSCriptRoot\Microsoft.SharePoint.Client.dll", 
    "$PSSCriptRoot\Microsoft.SharePoint.Client.Runtime.dll" 
    "System.Core" 
    ) 

Add-Type -TypeDefinition $cSharp -ReferencedAssemblies $assemblies 

$its = [SPClient.SharepointList]::GetList() 

不幸的是,在没有任何教程的情况下,我需要很长时间才能完全理解这种代码,所以如果你知道,请告诉我。

于 2013-07-16T13:40:53.413 回答