Un-Clone Sitecore Items
Other day I got a request to un-clone 100+ Sitecore items. Doing it manually through Content Editor is not a feasible option. so I thought of putting together a PowerShell script which can un-clone Sitecore items.
[Reflection.Assembly]::LoadFile("< wwwroot Directory>\Sitecore.Kernel.dll")
$root = Get-Item -Path "master:/sitecore/content/Home"
$props = @{
Parameters = @(@{Name="root"; Title="Choose the root"; Tooltip="Only items from this root will be returned."; } )
Title = "Clone Item Comparison Report"
Description = "Choose the root node."
Width = 550
Height = 300
ShowHints = $true
Icon=[regex]::Replace($PSScript.Appearance.Icon,"Office","OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}
$result = Read-Variable @props
if($result -eq "cancel") {
exit
}
$clonedItems=Get-ChildItem -Path $root.FullPath -Recurse
$CloneCollection = New-Object System.Collections.ArrayList
write-host 'start un-cloning the items...'
foreach($clonedItem in $clonedItems){
if($clonedItem.IsClone){
$ClonedProperties = [PSCustomObject] @{
ItemId = $clonedItem.ID;
ClonedItemName=$clonedItem.Name;
FullPath = $clonedItem.FullPath;
Source = $clonedItem."__Source";
SourceItem = $clonedItem."__Source Item";
}
$CloneCollection.Add($ClonedProperties)
$clonedItem.Editing.BeginEdit()
$itemUnClone = New-Object Sitecore.Data.Items.CloneItem($clonedItem)
$itemUnClone.Unclone()
$clonedItem.Editing.EndEdit()
}
}
write-host 'Generate clone comparison report'
if($CloneCollection.Count -ne 0){
$CloneCollection | Show-ListView -Property ItemId, ClonedItemName, FullPath, Source, SourceItem
}
write-host ' done!'
Disclaimer : Don't run this script on Production without validating it on Dev/Test.
Happy coding.
No comments:
Post a Comment