0

Attempting to bulk delete List Item using ProcessBatchData in a PowerShell script. Here is a command that my code is generating but I am getting an error when it executes. I have been unable to find the problem so I am hoping some CAML experts can shed some light as to what I am doing wrong.

$spWeb.ProcessBatchData("<?xml version='1.0' encoding='UTF-8'?><Batch><Method><SetList Scope='Request'>b37425b3-189d-4031-97f6-15e4ca767185</SetList><SetVar Name='ID'>480</SetVar><SetVar Name='Cmd'>Delete</SetVar></Method></Batch>");

Here is the Error:

Exception calling "ProcessBatchData" with "1" argument(s): "<nativehr>0x80070057</nativehr><nativestack></nativestack>"
At line:1 char:24
+ $spWeb.ProcessBatchData <<<< ("<?xml version='1.0' encoding='UTF-8'?><Batch><Method><SetList Scope='Request'>b37425b3-189d-4031-97f6-15e4ca767185</SetList><SetVar Name='ID'>480</SetVar><SetVar Name='Cmd'>Delete</SetVar></Method></Batch>");
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

2 Answers 2

2

It ended up being sloppy escape characters in my XML. Powershell uses backtick character to excape characters and I was using single quotes and other techniques. After switching to proper escaping character my command worked. See blog post here for more.

0

Try using <ows:Batch>:

<?xml version='1.0' encoding='UTF-8'?>
<ows:Batch OnError='Return'>
  <Method>
    <SetList Scope='Request'>b37425b3-189d-4031-97f6-15e4ca767185</SetList>
    <SetVar Name='ID'>480</SetVar>
    <SetVar Name='Cmd'>Delete</SetVar>
  </Method>
</ows:Batch>

<?xml version='1.0' encoding='UTF-8'?><ows:Batch OnError='Return'><Method><SetList Scope='Request'>b37425b3-189d-4031-97f6-15e4ca767185</SetList><SetVar Name='ID'>480</SetVar><SetVar Name='Cmd'>Delete</SetVar></Method></ows:Batch>

From Deleting Items using ProcessBatchData method

1
  • Aside from that, it appears that your CAML is well formed. The only similar issues I've found, the error is resolved by allowing unsafe updates, the error is caused by a read-only field, or the error is caused by a bad CAML-produced content type. Oct 18, 2012 at 17:57

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.