SharePoint 2010 update every Socond list item using Powershell SP.Client -


what need update every second item using powershell sharepoint.client. used code here http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/15/using-powershell-to-get-data-from-a-sharepoint-2010-list.aspx , added required functionality. im new in powershell may have made silly mistake. kindly check code , pointed mistake.

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 } 

thank in advance.

okay, i've managed solve it. can add update logic inside of c# block , call function.

it should looks this

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 client powershell"; item["userdata"] = "yeap 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()  

unfortunatly takes alot of time me understand kind of code without tutorials, if know such, please inform me.


Comments