Running version Sitecore 9.3
- and the latest version of the Powershell
package
The Powershell documentation has an example of deleting an individual item
.
$database = Get-Database -Name "master"
$archiveName = "recyclebin"
$archive = Get-Archive -Database $database -Name $archiveName
Remove-ArchiveItem -Archive $archive -ItemId "{1BB32980-66B4-4ADA-9170-10A9D3336613}"
Is it possible to have the Remove-archive item iterate through the whole list of archived items, but only delete items older than 1 year?
*** Edit I managed to put a solution together prior to both of the Sumits who posted, but their solutions are cleaner.
function GetRecycleBinItems {
$database = Get-Database -Name "master"
$archiveName = "recyclebin"
$archive = Get-Archive -Database $database -Name $archiveName
Get-ArchiveItem -Archive $archive
}
$limit = [datetime]::Now.AddDays(-365)
$items = GetRecycleBinItems
foreach($item in $items) {
if ($item.ArchiveDate -lt $limit) {
Remove-ArchiveItem -Archive $archive -ItemId $item.ItemId
}
}