1

Doing a lot of cleanup of versions and generating several reports. We are cleaning up versions on tons of items and I wanted to generate a report of the completed activity. I can get the item details out of either recyclebin or archive, but I haven't found a way to detail the version information (a count would probably be enough) of an item in the archive/recycle bin.

Item had 10 versions, we recycled 7. I'd like to be able to run a report against the recyclebin that provides the item details and the number of versions in the recycle bin. Item summary is no problem. But doesn't look like the versions details are exposed. It's available via the UI when you select and item, so there has to be some mechanism. Thoughts?

2 Answers 2

1

You can use below snippet to fetch archived items from database along with version numbers and count as below.

$database = [Sitecore.Configuration.Factory]::GetDatabase("master")
$archiveManager = [Sitecore.Data.Archiving.ArchiveManager]::GetArchive("archive",$database)

#fetch archive entries from page index 0 and page size 100.
$archiveEntries = $archiveManager.GetEntries(0,100);

$arrayOfArchivedItems = @()
$archiveEntries | ForEach {
    $itemVersions = $archiveManager.GetVersions($_.ItemId)
    
    $itemVersionNumbers = @()
    $itemVersions | ForEach {
        $itemVersionNumbers += $_.Version
    }
    
    $itemVersionSorted = $itemVersionNumbers | Sort-Object
    
    $obj = New-Object -TypeName PSObject
    $obj | Add-Member -Name 'Name' -MemberType Noteproperty -Value  $_.OriginalLocation
    $obj | Add-Member -Name 'VersionNumbers' -MemberType Noteproperty -Value  $itemVersionSorted
    $obj | Add-Member -Name 'VersionCount' -MemberType Noteproperty -Value  $itemVersionSorted.Count
    $arrayOfArchivedItems += $obj
}

$arrayOfArchivedItems | Format-Table

This returns the output as below containing item path, version numbers archived and count of versions archived.

enter image description here

Using similar way you can fetch details of recycle bin as well by setting the archive manager as below to fetch from 'recyclebin'.

$database = [Sitecore.Configuration.Factory]::GetDatabase("master")
$archiveManager = [Sitecore.Data.Archiving.ArchiveManager]::GetArchive("recyclebin",$database)

Hope this helps!!!

2
  • 1
    Wow, thanks for the extra detail and the framework. Minor tweak and plugs right into an existing framework I'm using. Really appreciate your time.
    – GregB
    Commented Jun 7 at 15:05
  • Glad to hear it helped. Thanks @Greg B
    – ckhanna
    Commented Jun 7 at 15:09
0

Once you have the recycle bin archive:

$database = [Sitecore.Configuration.Factory]::GetDatabase("master")
$archive = [Sitecore.Data.Archiving.ArchiveManager]::GetArchive("recyclebin", $database)

You can make a call to one of the archive's GetVersions() methods:

  1. IEnumerable<ArchiveItemVersion> GetVersions(ID itemId)
  2. IEnumerable<ArchiveItemVersion> GetVersions(Guid archivalId)
  3. IEnumerable<ArchiveItemVersion> GetVersions(Guid archivalId, User user)

Here is an example of passing in an item ID:

$yourItemId = [Sitecore.Data.ID]::Parse("{xxxx-xxxx-xxxx-xxxx-xxxx}")
$versions = $archive.GetVersions($yourItemId)

To show the data:

$versions | Select-Object | Format-List -Property *

The output will look like this:

ArchivalId : cbfb7e68-ec8f-46f7-bc4e-14d383780f2d
By         : sitecore\Admin
Date       : 6/1/2024 5:56:55 PM
ItemId     : {326D91B7-E18A-4287-8FB3-8BF1853AE863}
Language   : en
Version    : 11
VersionId  : 538b170d-7c92-4aff-ac5e-aa514af877ec

ArchivalId : cbfb7e68-ec8f-46f7-bc4e-14d383780f2d
By         : sitecore\Admin
Date       : 6/1/2024 5:57:24 PM
ItemId     : {326D91B7-E18A-4287-8FB3-8BF1853AE863}
Language   : en
Version    : 10
VersionId  : 3a05f10d-0dbf-442f-aba7-53a5075d6934

With this, you can create a solid report.

1
  • Thank you. I didn't find that in the docs anywhere and you are right, with that detail I should have everything I need. Many thanks.
    – GregB
    Commented Jun 7 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.