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>
            <FieldRef Name="RanUpdate" />
            <FieldRef Name="RanUpdate" />
            <Value Type="Boolean">False</Value>
$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
    if ($count -ge 1)
        foreach($item in $listitems)
            $item["Year"] = "2010"
            $item["RanUpdate"] = $true


1 Answer 1


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

  • 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 and acknowledge you have read our privacy policy.

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