Master To Web
PowerShell Extensions, Reports, Sitecore

Easily search for text in any field with this Sitecore Powershell Extensions Report

A common requirement for content authors in Sitecore is to be able to search for text across Sitecore items. This text can appear in any field and is useful when authors are performing audits or need to make a global change to previously published content. With this friendly Sitecore Powershell Extensions report, you can easily specify the root and search for any text, in any field.

The results are then displayed in easy to see report, allowing you to export the results as needed.

To start, you’ll need to make sure you have Sitecore PowerShell Extensions installed. You can find the latest version on the project GitHub.

To use the script, simply create a new PowerShell Sript item in your location of choice. For example, for the report to appear in Sitecore’s start menu (under SPE reports), create the report here:
/sitecore/system/Modules/PowerShell/Script Library/SPE/Reporting/Content Reports/Reports

$fieldRequiredValidator = {
        if([string]::IsNullOrEmpty($variable.Value)){
            $variable.Error = "Please provide a value."
        }
    }
    $dialogProps = @{
        Parameters = @(
            @{ Name = "searchRoot"; Title="Search Root"; Tooltip="The starting point when performing a search."; Source="Datasource=/sitecore/content/"; editor="droptree";},
            @{ Name = "fieldValue"; Value=""; Title="Search Text"; Tooltip="The value to search for"; Placeholder="Search String"; Columns=12; Validator=$fieldRequiredValidator;}
        )
        Description = "This report allows you to search the item fields for particular text and display the results"
        Title = "Search for Text"
        Width = 700
        Height = 575
        OkButtonName = "Proceed"
        CancelButtonName = "Abort"
        ShowHint = $true
        Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
    }
   
    $result = Read-Variable @dialogProps
       
    if($result -ne "ok") {
        Exit
    }
   
    $foundItems = @($searchRoot) + @($searchRoot.Axes.GetDescendants() | Initialize-Item)
    [System.Collections.ArrayList]$reportItems = @()
    foreach($currentItem in $foundItems) {
        $fieldsToUpdate = @{}
         Get-ItemField -Item $currentItem -ReturnType Field -Name $fieldName `
                | ForEach-Object{
                    $originalValue = $_.Value
                    if ($originalValue -match $fieldValue)  
                    {
                        $reportItems.Add($currentItem)
                    }  
                }
    }
   
    $reportProps = @{
        Property = @(
            "ID","Name","ItemPath","Language","Version"
        )
        Title = "Find Text Report"
        InfoTitle = "Report Details"
        InfoDescription = "The following report shows items found with the specified criteria."
    }
    $reportItems | Show-ListView @reportProps
    Close-Window

Related posts

Create a View Component for Sitecore XM Cloud, using the ASP.NET Core SDK 

Amir Setoudeh
3 weeks ago

View all of your personalizations in one place with Sitecore 9.2

Amir Setoudeh
6 years ago

Create a Global Header and Footer for your Sitecore website

Amir Setoudeh
6 years ago
Exit mobile version