Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell script to remove all content items for french version in sitecore

I wanna use this script to remove all content items for french version and leave the English version in sitecore but wanna make sure it looks good before excuting it :(

cd 'master:/sitecore/content'

function FilterItemsToProcess($item) 
{
    Get-Item $item.ProviderPath -Language "fr-CA"
}

$list = [System.Collections.ArrayList]@()
$itemsToProcess = Get-ChildItem -Recurse . | foreach {FilterItemsToProcess($_)}
if($itemsToProcess -ne $null)
{

    $itemsToProcess | ForEach-Object { 
        | remove-item
    }
}
like image 327
MirooEgypt Avatar asked Apr 28 '15 19:04

MirooEgypt


1 Answers

Miroo,

One thing you need to know is that Remove-Item always removed the item as a whole. It does not remove just the language even if you pipe a language specific version. This is because sitecore API always returns an item in a specific language and Remove-Item has no way of disregarding the intent.

What you need to use for the purpose is the Remove-ItemLanguage commandlet.

e.g. in the following example I'm creating a "Test" item in my content then adding a Polish version to each of those items and in the next step deleting the polish versions.

New-Item master:\content\ -ItemType "Sample/sample item" -Name test -Language en | Out-Null

foreach ($i in 1..10) {
    New-Item master:\content\test\ -ItemType "Sample/sample item" -Name $i -Language en | Out-Null
}

Get-ChildItem master:\content\test\ | Add-ItemLanguage -TargetLanguage pl-pl -IfExist Skip | Out-Null

Get-ChildItem master:\content\test\ | Remove-ItemLanguage -Language pl-pl

Your script could be as simple as following:

$path = "master:\content"
@(Get-Item $path) + (Get-ChildItem $path -Recurse) | Remove-ItemLanguage -Language "fr-CA"
like image 64
Adam Najmanowicz Avatar answered Nov 15 '22 07:11

Adam Najmanowicz