Common Pitfalls

Avoid these common mistakes when learning SPE.

Avoid these common mistakes when starting with SPE. Learning from others' errors will save you time and frustration.

Forgetting Item Editing Context

Items in Sitecore cannot be modified directly. You must use the editing context.

The Problem

  • Wrong: $item["Title"] = "New Title" (changes won't save!)

  • Correct:

    $item.Editing.BeginEdit()
    $item["Title"] = "New Title"
    $item.Editing.EndEdit()

Why It Matters

Without BeginEdit() and EndEdit(), changes are made to the in-memory object but never persisted to the database.

Best Practice Pattern

Always use try-catch to handle errors properly:

foreach($item in $items) {
    $item.Editing.BeginEdit()
    try {
        # Make your changes
        $item["Title"] = "New Title"
        $item["Text"] = "New content"

        # Commit changes
        $item.Editing.EndEdit()
    }
    catch {
        # Roll back on error
        $item.Editing.CancelEdit()
        Write-Error "Failed to update $($item.ItemPath): $_"
    }
}

Read more: Editing Items

Using Recursion on Large Trees

Using -Recurse carelessly can cause performance problems or even crash your session.

The Problem

Why It's Problematic

  • On large content trees, this can take minutes or hours

  • May consume excessive memory

  • Can cause session timeouts

  • Locks up the browser

Better Approaches

Option 1: Limit the Scope

Option 3: Limit Depth

Read more: Find-Item | Best Practices

Ignoring Security

SPE is powerful, which makes security critical.

Common Security Mistakes

  • NEVER run scripts from unknown sources

  • NEVER deploy SPE without reviewing security settings

  • NEVER install SPE on CD (Content Delivery) servers

  • ✅ Always review and understand scripts before running

  • ✅ Use role-based access control

  • ✅ Test in development first

Confusing PowerShell Comparison Operators

PowerShell uses different operators than most programming languages. See Language Basics for the complete comparison operator reference.

Examples

Learn more: Language Basics - Comparisons

Forgetting About Language Versions

Items in Sitecore can have multiple language versions, which affects querying and editing.

The Problem

Working with Languages

Read more: Item Languages

Suppressing Output Incorrectly

Different methods of suppressing output have very different performance characteristics.

The Problem

Performance Comparison

Next Steps

Now that you know what to avoid:

  1. Review your scripts: Look for these pitfalls in existing code

  2. Practice safely: Test in development before production

  3. Learn best practices: Read Best Practices

  4. Secure your installation: Complete the Security Checklist

Last updated