Created
March 2, 2016 21:35
-
-
Save AdamNaj/d86c3a5641ec5cb7e62f to your computer and use it in GitHub Desktop.
Archive old item versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Archive-OldItemVersion { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Position = 0,Mandatory = $true,ValueFromPipeline = $true)] | |
| [ValidateNotNullOrEmpty()] | |
| [Sitecore.Data.Items.Item]$Item, | |
| [Parameter(Position = 1,Mandatory = $true)] | |
| [ValidateNotNullOrEmpty()] | |
| [int]$MaxVersions | |
| ) | |
| process { | |
| while ($Item.Versions.Count -gt $MaxVersions) { | |
| $archive.ArchiveVersion($Item.Versions[$Item.Versions.GetVersionNumbers()[0]]); | |
| } | |
| } | |
| } | |
| # items underneath this path to be pruned | |
| $path = "master:\content" | |
| #languages can be defined specifically like "en", "pl-PL' or with wildcards like "*" | |
| $languages = "*" | |
| #Check how many versions are there in each language in each of the items before the trim | |
| Get-ChildItem $path -Language $languages -Recurse | ft name,language,@{ Name = "VerCount"; Expression = { $_.Versions.Count } } | |
| #ACTION HAPPENS HERE | |
| Get-ChildItem $path -Language $languages -Recurse | Archive-OldItemVersion -max 10 | |
| #Check how many versions are there in each language in each of the items after the trim | |
| Get-ChildItem $path -Language $languages -Recurse | ft name,language,@{ Name = "VerCount"; Expression = { $_.Versions.GetVersionNumbers().Length } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment