The Recycle Bin search in XM Cloud doesn’t work. Try this instead!



This content originally appeared on DEV Community and was authored by Kenneth McAndrew

I had someone ask me to restore an item from the recycle bin in XM Cloud today. Generally not a difficult task, assuming it hasn’t been 30 days since the deletion when it should get flushed. But, I’ve come to find that the recycle bin in XM Cloud, while it has a search, that search…doesn’t work. You get a script error.

Now, in the collection of tools, the recycle bin seems to be a relic of the “old” era – it’s in the Desktop of the Content Editor system, and I don’t as yet see an equivalent in Explorer or Pages. But it’s still a pretty useful tool. Fortunately, there’s another way to do this…good old Sitecore PowerShell.

I remembered from something else I was messing with once that there was a way to get into the recycle bin, so a little documentation and AI searching and crafting, and we get the following number. This script will both search for a term in the name or original path, and if you choose will restore the item(s) back to the master database. A quick little workaround for that pesky search problem!

$searchTerm = ""
$restoreItems = $false

$database = Get-Database -Name "master"
$archive = Get-Archive -Database $database -Name "recyclebin"

# Get all items in the recycle bin
$archiveItems = Get-ArchiveItem -Archive $archive |
    Where-Object {
        $_.Name -match $searchTerm -or
        $_.OriginalLocation -match $searchTerm
    }

foreach ($archivedItem in $archiveItems) {
    Write-Host "Found deleted item: $($archivedItem.Name) | ID: $($archivedItem.ArchivalId) | Path: $($archivedItem.OriginalLocation)"

    if ($restoreItems) {
        Restore-ArchiveItem -Archive $archive -ItemId $archivedItem.ArchivalId
        Write-Host "Restored deleted item: $($archivedItem.Name) | ID: $($archivedItem.ArchivalId) | Path: $($archivedItem.OriginalLocation)"
    }
}


This content originally appeared on DEV Community and was authored by Kenneth McAndrew