0

It takes forever to update items using foreach loop. Any other idea?

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$web=get-SPWeb "http://inside.nov.com/sites/sales/Apps"
$list=$web.Lists["Norton Security"]

$CAML = '<Where>
      <Or>
         <IsNull>
            <FieldRef Name="RanUpdate" />
         </IsNull>
         <Eq>
            <FieldRef Name="RanUpdate" />
            <Value Type="Boolean">False</Value>
         </Eq>
      </Or>
   </Where>'
$query = new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"

#$query.RowLimit = 10
$query.Query = $CAML
$listitems = $list.GetItems($query)
$count = $listitems.count

write-host $count
# End script
#Break
    if ($count -ge 1)
    {
        foreach($item in $listitems)
        {
            $item["Year"] = "2010"
            $item["RanUpdate"] = $true
            $item.SystemUpdate()
        }
    }

$web.dispose()

1 Answer 1

0

You can perform a batch operation to do updates on many ListItems at once. example.

2
  • Thanks. I am not sure if it will work in powershell. but will try. Jan 15, 2016 at 19:57
  • Worst case scenery you can execute C# from powershell. source
    – Gilgamesh
    Jan 15, 2016 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.