Retrieving Items

This page covers all the methods for finding and retrieving Sitecore items using SPE. Whether you need a single item or a collection, SPE provides flexible query options to meet your needs.

Core Cmdlets

Get-Item

Use Get-Item to retrieve a single item or items matching a query. This cmdlet throws an error if the item doesn't exist (unless using queries that may return zero results).

Key uses:

  • Retrieve a single item by path

  • Query items using Sitecore query

  • Get items by ID or URI

Get-ChildItem

Use Get-ChildItem to retrieve children and descendants of an item. This cmdlet is ideal for traversing content trees.

Key uses:

  • List immediate children

  • Recursively traverse item trees

  • Filter by template or other properties

Dynamic Parameters

SPE extends the standard PowerShell cmdlets with dynamic parameters. These appear when you specify a Sitecore database path:

Parameter
Description
Available On
Example

AmbiguousPaths

Show all items matching ambiguous criteria

Get-Item

-AmbiguousPaths

Database

Specify database when using ID

Get-Item

-Database "master"

ID

Match item by GUID

Get-Item, Get-ChildItem

-ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"

Language

Specify language versions

Get-Item, Get-ChildItem

-Language "en-US" or -Language *

Query

Execute Sitecore query

Get-Item

-Query "/sitecore/content//*"

Uri

Match item by ItemUri

Get-Item

-Uri "sitecore://master/{GUID}?lang=en&ver=1"

Version

Specify item versions

Get-Item, Get-ChildItem

-Version 2 or -Version *

WithParent

Include parent in results

Get-ChildItem

-WithParent

Retrieving by Path

The most common way to retrieve items is by their Sitecore path.

Example: Retrieve an item by path.

Output:

The /sitecore portion of the path is optional. Both master:\content\home and master:\sitecore\content\home work identically.

Example: The C# equivalent for reference.

Working with Languages

Retrieve items in specific languages or all languages using the -Language parameter with wildcards.

Example: Retrieve the Danish version of an item.

Output:

Example: Retrieve latest version for all languages.

Output:

Working with Versions

Retrieve specific versions or all versions using the -Version parameter.

Example: Retrieve all versions in all languages.

Output:

Example: Using wildcards for partial matches (all English variants).

Retrieving Children

Use Get-ChildItem to retrieve an item's children, with optional recursion.

Example: Retrieve immediate children only.

Example: Retrieve all descendants recursively.

Example: Retrieve children in all languages and versions.

Retrieving by ID

Use the -ID parameter to retrieve items by their GUID. This is useful when you know the item ID but not its path.

Example: Retrieve an item by ID.

Output:

When using -ID, you must specify the database path (e.g., master:) to activate the dynamic parameter.

Retrieving by URI

ItemUri encodes the database, item ID, language, and version in a single string.

Example: Retrieve an item by URI.

Output:

Sitecore Query

Use Sitecore query to find items matching complex criteria. This is more efficient than traversing the tree when you need specific items.

Example: Find all items with a specific template.

Output:

Example: Query with language and version wildcards.

Example: Query using dates (ISO format required) filtering by the publishing restriction where the item (not version) has a future date.

Fast Query

XPath with Axes

For complex queries using XPath axes, use the Sitecore API directly or prepend the context path.

Example: Use XPath axes to find ancestors.

Custom Property Sets

Use custom property sets with Select-Object to retrieve specific groups of properties.

Example: Retrieve security properties using PSSecurity.

Output:

Check out Item Security to learn about managing the security settings using SPE.

Example: Retrieve template information using PSTemplate.

Output:

Example: Retrieve image metadata using PSImage.

Output:

Example: Retrieve schedule information using PSSchedule.

Output:

Using Initialize-Item

If you retrieve items using the Sitecore API directly, wrap them with Initialize-Item to add SPE's automatic properties.

Example: Query using Sitecore API and wrap with SPE properties.

Common Retrieval Patterns

Pattern: Find Items by Template

Pattern: Find Recently Modified Items

Pattern: Find Items by Field Value

Pattern: Get All Media Items Above Size Threshold

Performance Tips

  • Use Sitecore query when you need specific items from a large tree

  • Use Get-ChildItem for small trees or when you need all items

  • Filter early - use query predicates instead of Where-Object when possible

  • Limit language/version retrieval - only use -Language * and -Version * when necessary

See Also

References

Last updated