3

I used Sitecore PowerShell Extensions module to create script, that copy the relation from one item to the related item.

I use Get-ChildItem to get all the items which will have relation on specific fields

Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -match $'myTemplate' -and $_.Fields[$fromfield].Value -ne $null -and $_.Fields[$fromfield].Value -ne "" } | ForEach-Object { } 

I took about 1 min to fetch all the items because the data is big.

So I tried to use Find-Item to make the search process faster

Find-Item -Index 'sitecore_mastre_index' -Where 'TemplateName = @0' -WhereValues 'myTemplate' 

It gave me below warning, note that I use Sitecore Version 7.2

WARNING: The parameter Where is not supported on this version of Sitecore due to platform limitations.

This parameter is supported starting from Sitecore Version 7.5

Is there a way to retrieve the data using PowerShell in way faster than using Get-ChildItem?

Note: if I use Get-Item . the query returns only the first 100 items. I have many more items.

1
  • Hard to tell without knowing more about your variables. Have you tried the exclude/include/filter parameters of Get-Childitem? Commented Dec 28, 2015 at 15:49

1 Answer 1

5

There are a few things to consider.

Example: Get-ChildItem

# Essentially touches all of the items in the database. # It's one of the most common ways to query the items, # but should be a narrow path. Get-ChildItem -Path "master:\" -Recurse 

Example: Find-Item

# This example is what you need to query the index. # You can chain together multiple Criteria by making a comma separated list of hashtables. # Piping to the Initialize-Item command will convert SearchResultItem to Item. # PS master:\> help Find-Item -Examples Find-Item -Index sitecore_master_index -Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Sample Item"} | Initialize-Item 

Example: Get-Item with fast query

# This example takes advantage of the fast query. Substitute for your use case. $query = "fast:/sitecore//*[@@templatename='Sample Item']" Get-Item -Path "master:" -Query $query 

The book we've put together may also prove beneficial. https://www.gitbook.com/book/sitecorepowershell/sitecore-powershell-extensions/details

Sign up to request clarification or add additional context in comments.

2 Comments

the syntax fast:/ does not work any longer within Sitecore 9.02... any idea or workaround? changing the fast query to a slow query, it applies the maximum returned result of 100....
Try it and let me know if it works for you, since what was working on Sitecore 7.5 stopped working on 9.02 not sure if the issue is with PowerShell or Sitecore itself...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.