Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
    
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. –  RJ Cuthbertson Oct 18 '12 at 17:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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