Editing Items

This page covers all methods for updating Sitecore items using SPE, from simple property changes to complex field type handling and bulk operations.

Overview

SPE provides multiple ways to edit items, each suited to different scenarios:

  • Automated Properties - Simple, intuitive syntax for single-field updates

  • Set-ItemProperty - PowerShell-standard cmdlet for property updates

  • BeginEdit/EndEdit - Explicit editing for multiple fields or special cases

  • BulkUpdateContext - High-performance updates for large datasets

Automated Properties

The most convenient way to edit items is through SPE's automated properties. These properties automatically handle BeginEdit and EndEdit operations.

Example: Update a field using automated properties.

$item = Get-Item -Path "master:\content\home"
$item.Title = "New Title"

Example: Update a field with spaces in the name.

$item = Get-Item -Path "master:\content\home"
$item."Closing Date" = [datetime]::Today

Field names containing spaces must be wrapped in quotes (single or double).

Example: Update system fields.

Example: Dynamically reference fields by variable.

Using Set-ItemProperty

The PowerShell-standard approach using Set-ItemProperty is also supported.

Example: Update a property using Set-ItemProperty.

Manual Edit Context

For multiple field updates or special scenarios, use explicit BeginEdit and EndEdit calls.

Example: Update multiple fields in a single edit context.

Example: Safe edit context with error handling.

Working with Field Types

SPE provides intelligent handling for different Sitecore field types through automated properties.

DateTime Fields

DateTime fields automatically convert between Sitecore's string format and .NET DateTime objects.

Example: Read and write DateTime fields.

Image Fields

Image fields accept item references from the Media Library.

Example: Assign an image to an Image field.

Link fields accept item references and automatically create the link XML.

Example: Assign a content item to a GeneralLink field.

Multi-Value Fields

Multi-value fields (Multilist, Treelist, etc.) accept arrays of items.

Example: Assign multiple items to a list field.

Result in Content Editor:

ItemList Assignment

Accessing Typed Fields

Use the ._ or .PSFields property to access strongly-typed field objects.

Example: Access typed Image field properties.

Example: Access typed LinkField properties.

Output:

Example: Find all TextField instances on an item.

When to Use Each Method

Use Automated Properties When:

  • Updating a single field or a few fields

  • Readability is important

  • Working with small datasets

Example:

Use BeginEdit/EndEdit When:

  • Updating many fields on a single item

  • Needing explicit control over save timing

  • Working with system properties (like BranchId)

Example:

Use BulkUpdateContext When:

  • Updating many items (hundreds or thousands)

  • Performance is critical

  • You need to bypass certain Sitecore events

Example:

Bulk Update Patterns

Pattern: Update Items with BulkUpdateContext

Pattern: Update with Progress Reporting

Pattern: Conditional Updates

Pattern: Update from CSV Data

Using Context Switchers

SPE provides the New-UsingBlock function for working with Sitecore context switchers and disposable objects.

Example: Generate relative URL with site context.

Common Context Switchers

Use these classes with New-UsingBlock for various scenarios:

  • Sitecore.SecurityModel.SecurityDisabler - Bypass security checks

  • Sitecore.Data.BulkUpdateContext - Optimize bulk updates

  • Sitecore.Globalization.LanguageSwitcher - Switch language context

  • Sitecore.Sites.SiteContextSwitcher - Switch site context

  • Sitecore.Data.DatabaseSwitcher - Switch database context

  • Sitecore.Security.Accounts.UserSwitcher - Switch user context

  • Sitecore.Data.Items.EditContext - Item editing context

  • Sitecore.Data.Proxies.ProxyDisabler - Disable proxies

  • Sitecore.Data.DatabaseCacheDisabler - Disable database cache

  • Sitecore.Data.Events.EventDisabler - Disable events

Example: Read items with security disabled (use with caution).

Example: Update items with events disabled.

Advanced Editing Scenarios

Update Items in Different Language

Update Specific Version

Copy Field Values Between Items

Update Standard Values

Performance Optimization

Avoid: Repeated Automated Property Updates

Prefer: Explicit BeginEdit/EndEdit

Best: BulkUpdateContext for Large Datasets

Common Pitfalls

Pitfall: Forgetting to End Edit

Pitfall: Modifying System Fields Without Care

Pitfall: Assuming Item Exists

See Also

References

Last updated