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.