2

I'm getting this error while running a powershell extension script in Sitecore. Here's a simple version of the script.

$allContent = Get-ChildItem -Path "/sitecore/content/Website/Home" -Recurse
Write-Host $allContent.Length" content items found!"
$numUpdated = 0
foreach ($content in $allContent){
    $body = $content["Body"]

    if ($body -like '*FindThis*'){
        Write-Host "Found pattern in"$content.ItemPath
        $body = $body -replace 'FindThis', 'ReplaceWithThis'
        $content.Editing.BeginEdit()
        $content["Body"] = $body
        $content.Editing.EndEdit() | Out-Null;
        $numUpdated++
    }
}
Write-Host "Total number of items updated: "$numUpdated

The odd thing is that the script will work fine for a certain number of items at the beginning of the loop, but then it will start printing the same error for the rest of the array.

Exception calling "BeginEdit" with "0" argument(s): "The current user does not have write access to this item. User: sitecore\virtualssuser, Item: example-item ({645C2FB1-2877-49F8-89C6-E1FF92C3B1EC})"

If I run the script again, it will once again run fine for a certain number of items but then produce errors once it randomly hits a certain item. The only way to complete all items in the loop is to keep running the script over and over until it finally completes every one of them. Any idea what may be happening? I want the script to finish the loop the first time through.

  • Are you running this from within the ISE? Is there something common between each item that fails? – Michael West Aug 12 at 20:50
3

I found an article that shows a similar error message.

I'm guessing there is some underlying issue with the Sitecore API that results in this error.

New-UsingBlock(New-Object Sitecore.SecurityModel.SecurityDisabler){
    New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
        # Add your code here with really good logging because of scope.
    }
}

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.