When to use which parameters?

You might have noticed that there are 2 ways of filtering items.

Using the -Criteria parameter,

and using the -Where and -WhereValues parameters

This is due to the new capabilities introduced in Sitecore 7.5 which were not available before that version was released, namely integration of the Dynamic LINQ library. While the -Criteria approach is limited to string values, the -Where filtering allows you to use proper objects. Because this capability is only available starting with Sitecore 7.5 – if you attempt to use the -Where parameter on an older version – the cmdlet will fail to yield any results and you will see an appropriate warning message instead.

Let’s examine how you would do similar searches using both parameter sets. Let’s find all Template fields defined in English. For the sake of time saving let’s return only first 10 items in both cases.

As you can see the -Where approach is much simpler to understand, and while we don’t use it here – the -WhereValues can be proper objects like dates. This enables you to search for items that are e.g. older than a week.

But I’m not getting items from the cmdlet!

Straight from the commandlet you’re getting the Sitecore.ContentSearch.SearchTypes.SearchResultItem objects rather than full blown Sitecore Items. It’s done this way so you can do lightweight searching and filtering and only convert the final results to items. If you recall we’ve always had a Wrap-Item commandlet that has recently been renamed to Initialize-Item (old name still available as an alias). This commandlet has been extended to support SearchResultItem as an input from the pipeline. Consequently you can do the following with the above search to get the proper Items you can work with: