Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Find special characters through all rendering components

With this powershell command you will be to find special characters through all rendering components.




Import-Function -Name ConvertTo-Xlsx

$startPath = "master:/sitecore/content"
#Write-Host "Search started $(Get-Date -format 'u')"

$list = [System.Collections.ArrayList]@()
$itemsToProcess = Get-ChildItem $startPath -Language * -Recurse
if($itemsToProcess -ne $null) {
    $itemsToProcess | ForEach-Object { 
        $match = 0;
        foreach($field in $_.Fields) {
            
            if(($field.Type -eq "Single-Line Text") -or ($field.Type -eq "Rich Text") -or ($field.Type -eq "Image") -or ($field.Type -eq "General Link"))
            {
                if($field -match '^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$') {
                    $info = [PSCustomObject]@{
                        "path"=$_.ID
                        "1"=","
                        "Template"=$_.TemplateName
                        "2"=","
                        "FieldName"=$field.Name
                        "3"=","
                        "FieldType"=$field.Type
                        "4"=","
                        "Value"=$field.Value
                    }
                    [void]$list.Add($info)
                }
            }
        }
    }
}
#Write-Host "Search ended $(Get-Date -format 'u')"
#Write-Host "Items found: $($list.Count)"
#$list | Format-Table

[byte[]]$outobject =  $list | ConvertTo-Xlsx 
Out-Download -Name "report_Find special_characters_through_all_rendering_components.xlsx" -InputObject $outobject

Posted: 22/06/2022 5:35:04 p.m. by Gitesh Shah | with 0 comments