The Find-Item command searches for items using the Sitecore Content Search API. The type SearchResultItem is used as the type when working with IQueryable.
Number of search results to be skipped skip before returning the results commences.
Aliases
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Property <String[]>
An array of property names which match with the SearchResultItem type.
Note: The use of Initialize-Item is not supported because the object returned is no longer a SearchResultItem and therefore unable to guarantee that Item objects can be returned. #1123
Aliases
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Template <String[]>
An array of template path names relative to the -Path.
Aliases
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-LatestVersion <SwitchParameter>
Specifies that the latest item version should be returned.
Aliases
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Path <String>
Specifies the root directory to find items.
Aliases
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
Outputs
The output type is the type of the objects that the cmdlet emits.
Fields by which filtering can be performed using the -Criteria parameter.
EXAMPLE 2
Find items using a search built by the Query Builder field.
EXAMPLE 3
Find all items of template "Sample Item" which are in "English" under the "Home" item using Dynamic LINQ syntax.
EXAMPLE 4
Find items using a complex search predicate.
EXAMPLE 5
Find items using logical AND conditions with ContainsAny. Demonstrates that different array types are handled.
Note: When searching for IDs you can use the proper type like [ID[]]@("{C852E80E-ED49-4354-A397-6F66487F0E26}") so SPE will handle the conversion to ShortID.
EXAMPLE 6
Find items using logical AND with ContainsAll. Demonstrates looking in multilist fields.
EXAMPLE 7
Find an item by ID.
EXAMPLE 8
Find items within a data range. Possible filters are InclusiveRange and ExclusiveRange . When using dates, only yyyyMMdd is considered in the comparison so no need to get too precise.
EXAMPLE 9
Find and count all items beneath a root item using the item path.
EXAMPLE 10
Find and count all items beneath a root item using the item id.
EXAMPLE 11
Find items and sort (boost) based on the date field. If this were used on a field containing future dates you should expect to see them mixed with past dates. This example demonstrates using Solr functions.
EXAMPLE 12
Find items where the created date is older than the specified time in UTC.
EXAMPLE 13
Find items where the title contains the specified value. A custom implementation of SearchResultItem is used to enable the use of the property Title in the Dynamic Query.
EXAMPLE 14
Find items where the path contains the specified Id and base templates contain the specified Id using a Dynamic Query. A custom implementation of SearchResultItem is used to enable the use of the property TemplateIds in the Dynamic Query.
EXAMPLE 15
Find items where the title contains "Sitecore" using a Scope Query. A custom implementation of SearchResultItem is used to enable the use of the property Title in the Scope Query.
EXAMPLE 16
Find items where the template is "Sample Content" and the title contains "Sitecore" and created by "admin" using the Criteria Query. A custom implementation of SearchResultItem is used to enable the use of the property Title and Creator in the Dynamic Query.
EXAMPLE 17
Find items matching a complex query. A custom implementation of SearchResultItem is used to enable the use of the property Title in the Predicate Query.
EXAMPLE 18
Find items under the Content tree where the language is "en" and there are more than two occurrences. This could be used to find duplicate item names at the same path.
EXAMPLE 19
Find the most recently updated item.
EXAMPLE 20
Find items where the expiration date has not passed (now to the future) or the expiration date is empty (never expires).
EXAMPLE 21
Use Skip and Take to page through results until all are returned.
class TitleSearchResultItem : SearchResultItem
{
[Sitecore.ContentSearch.IndexField("title")]
[string]$Title
}
$props = @{
Index = "sitecore_master_index"
Where = "Title.Contains(@0)"
WhereValues = "great"
QueryType = [TitleSearchResultItem]
}
Find-Item @props
class TemplatesSearchResultItem : SearchResultItem
{
# For items contained within an SXA index try using the name "inheritance_sm".
[Sitecore.ContentSearch.IndexField("_templates")]
[System.Collections.Generic.List[ID]]$TemplateIds
}
$props = @{
Index = "sitecore_master_index"
Where = "Paths.Contains(@0) And TemplateIds.Contains(@1)"
WhereValues = [ID]::Parse("{371EEE15-B6F3-423A-BB25-0B5CED860EEA}"), [ID]::Parse("{B0B6FB08-6BBE-43F2-8E36-FCE228325B63}")
QueryType = [TemplatesSearchResultItem]
}
Find-Item @props
class TitleSearchResultItem : SearchResultItem
{
[Sitecore.ContentSearch.IndexField("title")]
[string]$Title
}
$props = @{
Index = "sitecore_master_index"
ScopeQuery = "location:{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9};custom:title|Sitecore"
QueryType = [TitleSearchResultItem]
}
Find-Item @props | Select-Object -Property Title
class TitleSearchResultItem : SearchResultItem
{
[Sitecore.ContentSearch.IndexField("title")]
[string]$Title
[Sitecore.ContentSearch.IndexField("_creator")]
[string]$Creator
}
$criteria = @(
@{Filter = "Equals"; Field = "_templatename"; Value = "Sample Content"},
@{Filter = "Contains"; Field = "Title"; Value = "Sitecore"},
@{Filter = "Contains"; Field = "_creator"; Value = "admin"}
)
$props = @{
Index = "sitecore_master_index"
Criteria = $criteria
QueryType = [TitleSearchResultItem]
}
Find-Item @props
class TitleSearchResultItem : SearchResultItem
{
[Sitecore.ContentSearch.IndexField("title")]
[string]$Title
}
$criteriaTemplate = @{Filter = "Equals"; Field = "_templatename"; Value = "Template Field"; }, @{Filter = "Equals"; Field = "_templatename"; Value = "Sample Item"; Boost=25; }, @{Filter = "Equals"; Field = "_templatename"; Value = "Sample Content"; }
$predicateTemplate = New-SearchPredicate -Operation Or -Criteria $criteriaTemplate -QueryType ([TitleSearchResultItem])
$criteriaContent = @{Filter = "Contains"; Field = "Title"; Value = 'Sitecore'}
$predicateTitle = New-SearchPredicate -Criteria $criteriaContent -QueryType ([TitleSearchResultItem])
$predicateTemplateAndTitle = New-SearchPredicate -First $predicateTemplate -Second $predicateTitle -Operation And -QueryType ([TitleSearchResultItem])
$root = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
$criteriaRoot = @{Filter = "DescendantOf"; Value = $root }
$predicateRoot = New-SearchPredicate -Criteria $criteriaRoot -QueryType ([TitleSearchResultItem])
$predicate = New-SearchPredicate -First $predicateRoot -Second $predicateTemplateAndTitle -Operation And -QueryType ([TitleSearchResultItem])
$props = @{
Index = "sitecore_master_index"
WherePredicate = $predicate
QueryType = [TitleSearchResultItem]
}
Find-Item @props