in

How to Search for Text in Sitecore Using PowerShell

If you’ve ever needed to find where a specific word, phrase, or HTML snippet appears inside your Sitecore content, you know how time-consuming it can be. Between pages, components, and data sources, text can live in dozens of different places.

Using Sitecore PowerShell Extensions (SPE), you can automate this process and search for any text across all Sitecore items, including fields, layout XML, and component data sources.

Why Use PowerShell to Search in Sitecore

Manually checking hundreds of items is inefficient. With PowerShell, you can:

  • Find specific text instantly across all Sitecore content items
  • Search inside component renderings and data sources
  • Save results for auditing or cleanup tasks
  • Speed up content QA and SEO optimization

This method is ideal for content audits, migration reviews, and site-wide text replacements.

Requirements

Before running the script, make sure you have the following:

  • Sitecore PowerShell Extensions (SPE) installed
  • Access to the Master database
  • Permission to execute scripts

Step 1: Open PowerShell ISE in Sitecore

  1. Log in to Sitecore.
  2. Go to Desktop → Development Tools → PowerShell ISE.
  3. Select the Master database.
  4. Create a new script.

Step 2: Add the PowerShell Script

Copy the following script into the PowerShell ISE editor:

$searchText = "Your search text here"
$rootPath = "master:/sitecore/content"

Write-Host "Searching for occurrences of '$searchText'..." -ForegroundColor Cyan

$items = Get-ChildItem -Path $rootPath -Recurse

foreach ($item in $items) {
    # Check standard text fields
    foreach ($field in $item.Fields) {
        if ($field.Type -in @("Single-Line Text", "Rich Text", "Multi-Line Text")) {
            if ($field.Value -match [regex]::Escape($searchText)) {
                Write-Host "Found in Item: $($item.Paths.FullPath)" -ForegroundColor Green
                Write-Host "Field: $($field.Name)" -ForegroundColor Yellow
            }
        }
    }

    # Check layout details (__Renderings / __Final Renderings)
    $renderingFields = @("__Renderings", "__Final Renderings")
    foreach ($layoutField in $renderingFields) {
        $layoutValue = $item[$layoutField]
        if ([string]::IsNullOrEmpty($layoutValue) -eq $false) {
            if ($layoutValue -match [regex]::Escape($searchText)) {
                Write-Host "Found in Layout XML on: $($item.Paths.FullPath)" -ForegroundColor Cyan
            }

            # Parse data source IDs and search in those items
            $xml = $layoutValue
            $dataSourceIds = $xml.LayoutDefinition.Devices.Device.Renderings.Rendering.datasource | Where-Object { $_ -ne "" }
            foreach ($id in $dataSourceIds) {
                $dsItem = Get-Item -Path "master:" -ID $id -ErrorAction SilentlyContinue
                if ($dsItem) {
                    foreach ($dsField in $dsItem.Fields) {
                        if ($dsField.Type -in @("Single-Line Text", "Rich Text", "Multi-Line Text")) {
                            if ($dsField.Value -match [regex]::Escape($searchText)) {
                                Write-Host "Found in Data Source Item: $($dsItem.Paths.FullPath)" -ForegroundColor Magenta
                                Write-Host "Field: $($dsField.Name)" -ForegroundColor Yellow
                            }
                        }
                    }
                }
            }
        }
    }
}

This script searches for your target text inside:

  • Standard text fields (Single-Line, Multi-Line, Rich Text)
  • Layout XML fields (__Renderings, __Final Renderings)
  • Component data source items

Step 3: Adjust the Search Variables

At the top of the script, you can modify two key variables:

  • $searchText — the exact text or phrase you want to locate
  • $rootPath — where to start searching, such as: master:/sitecore/content/Home

Using a specific starting path improves performance and helps focus your search.

Step 4: Run the Script

  1. Click Run in the PowerShell ISE.
  2. The results will display in the console window.

Example output:

Found in Item: /sitecore/content/Home/About
Field: Body Text
Found in Data Source Item: /sitecore/content/Components/PromoBanner
Field: Promo Text

You’ll see which items and fields contain your search term, including any component data sources.

Step 5: Export Results to CSV (Optional)

For reporting or auditing, you can export results to a CSV file by adding this snippet:

$results = @()

# Inside your loop when matches are found:
$results += [pscustomobject]@{
    ItemPath = $item.Paths.FullPath
    FieldName = $field.Name
    Source = "Main Item"
}

# After the loop:
$results | Export-Csv -Path "C:\SitecoreTextSearchResults.csv" -NoTypeInformation
Write-Host "Results exported to C:\SitecoreTextSearchResults.csv"

This creates a CSV file listing all matches, which you can filter or sort in Excel.

Pro Tips for Sitecore PowerShell Users

  • Always test scripts on a non-production instance first.
  • Save your script as a Sitecore PowerShell Report for reusability.
  • Adjust field types if your implementation uses custom ones.
  • Combine this script with automated content audits or broken link checks.

Conclusion

With Sitecore PowerShell Extensions, you can locate any text across your site in minutes. This script searches not only page fields but also component-level data sources, making it a powerful maintenance and audit tool for developers and content managers alike.

Use it for:

  • Site content cleanup
  • SEO keyword verification
  • HTML snippet detection
  • Content migration audits

By automating text searches in Sitecore, you save hours of manual effort while maintaining consistency across your digital experience.

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

How to be an effective project manager?

How to Manage and Update Robots.txt in Sitecore for Test and Subdomain Environments