If I run each line individually, it works. But If I try to run the script with the for each loop, I get: Exception calling "Update" with "0" argument(s): "Value does not fall within the expected range."


 $listItems = $list.GetItems($query)
   $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

 foreach($item in $listItems)
             # DeleteItems
             # UpdateItems
             # CancelWorkflows
             $reason = $item["Reason"] + "  -- This Exception was open more than 30 days and will be closed by the administrator"
             $item["Reason"] = $reason
             Write-Host "Added Reason Code - $($item.ID)"
              $reason = $null
              $count = $count+1

Do I need to update a different way? When I break and check the variables, $item["Reason"] is empty so it makes sense that I have 0 arguments.

More Info: There are some columns that are required. There is a chance one of them may be empty and so the item can't be updated unless that field has a value. Can I force an update to an item even if a required field is blank?

  • 1. Updating an item by code with some required field missing is not a problem. 2. $reason being empty is not what's mentionned by the error message, that simply states the error occurs on Update() (aka "Update" with "0" argument(s)). So the truth is elsewhere...
    – Evariste
    Jul 3, 2019 at 19:07
  • So how can I ensure there is an argument to update? If I break the code and ask what is in $item.["Reason"] it is empty. I thought that is that the error meant, "there is nothing to update"
    – Jammin4CO
    Jul 3, 2019 at 19:22

1 Answer 1


OK, following my comment above, I had another thought for the problem. It's probably your new $reason value being longer than 255 characters. If your Reason field is a single-line text field, it cannot contain a string >255 char, hence the error message.

  • It is a Notes type field, rich text multiline, but I appreciate the insight.
    – Jammin4CO
    Jul 3, 2019 at 19:19
  • rich text multiline means it expects some HTML-formatted text. Maybe there's something wrong in your text, like a character-sequence forbidden in HTML? I'd dump the value of $reason right before calling Update: I'd bet you'd find something in the last $reason printed out right before the error is raised.
    – Evariste
    Jul 3, 2019 at 20:43

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.