Skip to content

Instantly share code, notes, and snippets.

@technomaz
Last active August 2, 2018 01:42
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save technomaz/58890edff903123083c77ad8f1b1b2e2 to your computer and use it in GitHub Desktop.
Sitecore Powershell script to restore items from recycle bin archived after a certain date (e.g. recently deleted)
[datetime]$archivedDate = [datetime]::Today.AddDays(-1)
Write-Host "Restoring items recycled after $($archivedDate.ToShortDateString())"
foreach($archive in Get-Archive -Name "recyclebin") {
Write-Host " - Found $($archive.GetEntryCount()) entries"
$entries = $archive.GetEntries(0, $archive.GetEntryCount())
foreach($entry in $entries) {
if($entry.ArchiveLocalDate -ge $archivedDate) {
Write-Host "Restoring item: $($entry.OriginalLocation) {$($entry.ArchivalId)}on date $($entry.ArchiveLocalDate)"
$archive.RestoreItem($entry.ArchivalId)
} else {
Write-Host "Skipping $($entry.OriginalLocation) on date $($entry.ArchiveLocalDate)"
}
}
}
@michaellwest
Copy link

This script just saved my bacon. Thanks man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment