Sitecore 刪除多版本

<#
This script will remove old versions of items in all languages so that the items only contains a selected number of versions.

>

item = Get-Item -Path "master:\content"dialogProps = @{
Parameters = @(
@{ Name = "item"; Title="Branch to analyse"; Root="你的節(jié)點路徑"},
@{ Name = "count"; Value=10; Title="Max number of versions"; Editor="number"},
@{ Name = "remove"; Value=$False; Title="Do you wish to remove items?"; Editor="check"}
)
Title = "Limit item version count"
Description = "Sitecore recommends keeping 10 or fewer versions on any item, but policy may dictate this to be a higher number."
Width = 500
Height = 280
OkButtonName = "Proceed"
CancelButtonName = "Abort"
}

$result = Read-Variable @dialogProps

if($result -ne "ok") {
Close-Window
Exit
}

items = @() Get-Item -Path master: -IDitem.ID -Language * | ForEach-Object { items += @() + @((_.Axes.GetDescendants())) | Where-Object {.Versions.Count -gt count } | Initialize-Item }ritems = @()
items | ForEach-Object {webVersion = Get-Item -Path web: -ID _.ID -Language.Language
if (webVersion) {minVersion = webVersion.Version.Number -count
ritems += Get-Item -Path master: -ID
.ID -Language _.Language -Version * | Where-Object {.Version.Number -le minVersion } } } if (remove) {
toRemove =ritems.Count
ritems | ForEach-Object {
| Remove-ItemVersion
}
Show-Alert "Removed toRemove versions" } else {reportProps = @{
Property = @(
"DisplayName",
@{Name="Version"; Expression={_.Version}}, @{Name="Path"; Expression={_.ItemPath}},
@{Name="Language"; Expression={_.Language}} ) Title = "Versions proposed to remove" InfoTitle = "Sitecore recommendation: Limit the number of versions of any item to the fewest possible." InfoDescription = "The report shows all items that have more than <b>count versions</b>."
}
$ritems | Show-ListView @reportProps
}

Close-Window

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容