Saturday, March 17, 2018

Sitecore Powershell:: Dictionary Audit Series -1

List of Dictionary Items against each language on the website.

I’ve created this PowerShell script to get the report of the list of dictionary items against each language. It gets the input of the path which we need to get the report.

Fields in the report:
1.       Dictionary key
2.       All the languages in the web database. (My site has only English and Arabic)

Script:
$root = Get-Item -Path (@{$true="master:\system\Dictionary\"; $false="master:\system\"}[(Test-Path -Path master:\system\Dictionary)])
$props = @{
        InfoTitle = "Dictionary Items"
        InfoDescription = "Lists of Dictionary Items"
        PageSize = 250
        Title = "Dictionary Items Report"
    }
$result = Read-Variable -Parameters `
    @{Name="root"; title="Items under"; Tooltip="choose the below path for searching dictionary items"} `
    -Description "This dialog shows search path of dictionary items" `
    -Title "Search Dictionary" -Width 500 -Height 300 -ShowHints

if($result -eq "cancel"){
    exit;
}
$items= [Sitecore.Data.Managers.LanguageManager]::GetLanguages([Sitecore.Data.Database]::GetDatabase("web"))

$reportItems = @()
$dictionaryitems = Get-ChildItem  -Path $root.ProviderPath -Recurse | Where-Object { $_.TemplateName -match "Dictionary entry"  }
if($dictionaryitems.Count -eq 0) {
    Show-Alert "There are no dictionaryitems"
} else {
foreach($dictionaryitem in $dictionaryitems){
$h=@{}
$h.add("Key",$dictionaryitem.Fields["Key"])
foreach($item in $items){
if($dictionaryitem.Database.GetItem($dictionaryitem.ID,$item) -ne $Null ){
$h.add($item.Name,$dictionaryitem.Database.GetItem($dictionaryitem.ID,$item).Fields["Phrase"])
}
}
$reportItem = [pscustomobject]$h
$reportItems += $reportItem
}

$properties = $reportItems[0].PSObject.Properties | foreach-object {$_.Name}

$reportItems | Show-ListView -Property $properties
}
Close-Window

Step1:

Step 2:


 Step 3:

 Step4:


 Download the Sitecore package: List of Dictionary items against each language




No comments:

Post a Comment