I have a script that goes and queries a string from a field box.

Issue: This script takes too long! How can I improve the time to get results?

Set-Location master:
Get-ChildItem -Path "master:\\sitecore\content" -Language * -Recurse -Force | 
    ForEach-Object -Process {
        if ($_.InnerData.Fields | Where-Object {$_.value -match 'Dynamics CRM'}) {
            $_.Paths.FullPath | Write-Log 
  • How many items are in your content tree? This would have to recurse through all of them, yes? If you have a lot of items, it's going to take a long time.
    – Ed Schwehm
    Jun 12, 2018 at 20:11

2 Answers 2


From what I can tell given the above, you are trying to search the entire tree for instances of Dynamics>CRM and writing the path to a log, you might see some better times from a fast:// query since it does not care about order given the tree compared to the Get-ChildItem:

$query = "fast:/sitecore/content//*[@Field1 = 'Dynamics>CRM' or @Field2 = 'Dynamics>CRM']"
Get-Item -Path "master:" -Language * -Query $query | ForEach-Object { $_.Paths.FullPath | Write-Log } 

You could also try and leverage your indexes:

$root = (Get-Item "master:/sitecore/content/")
Find-Item -Index sitecore_master_index `
          -Criteria @{Filter = "DescendantOf"; Field = $root },
                    @{Filter = "Contains"; Field = "field1"; Value = "Dynamics>CRM"},
                    @{Filter = "Contains"; Field = "field2"; Value = "Dynamics>CRM"} |
    Initialize-Item | ForEach-Object {$_.Paths.FullPath | Write-Log }

I would say the only real deviation from my above scripts to what you provided is defining fields to search by compared to just searching all things everywhere. That tidbit alone might help you speed things up.

  • Thank you, but how can I query a string from a text box (for example in Full Width Paragraph: Script search for Dynamics CRM --- and in Full Width box there is a string containing Dynamics CRM - which will return the template Path. Is this possible?
    – Heng Yon
    Jun 13, 2018 at 22:02
  • What is the Full Width box, is it a field on an item? If so you should be able to swap out Field1 for Full Width box or field1 for full_width_box respectively in the snippets above. The output will be the item path, similar to your original post.
    – vandsh
    Jun 13, 2018 at 22:31

A non-SPE approach is to use the out-of-the-box Search tab.

  1. Select the /sitecore/Content item
  2. Type in the search box custom: (tab)
  3. Type fieldname|Dynamics>CRM
  4. Search

It should return all items with a field of fieldName with a value of Dynamics>CRM. It has the added benefit of using the index by default, so it will be very quick. This doesn't write to the log, but perhaps that wasn't a requirement.

Search And Replace

From the search tab, you can also replace values.

Search and Replace

Type in the existing word (Dynamics>CRM) and the replacement.

Replacement Word

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.