Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Powershell query to find a link in content tree

With this powershell command you will be to  find a link in content tree.


 

Import-Function -Name ConvertTo-Xlsx
 
$startPath = "master:/sitecore/content/projectName/Home/home/tasks"
#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 'www.projectname.co.nz/something') {#can be any regex value here
                    $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 "ReportFindClassicLink.xlsx" -InputObject $outobject

Posted: 16/10/2022 5:06:25 p.m. by Gitesh Shah | with 0 comments