For the complete documentation index, see llms.txt. This page is also available as Markdown.

Creating and Removing Items

This page covers how to create new items and remove existing items using SPE.

Creating Items

Use New-Item to create new Sitecore items. The cmdlet requires a path or parent item, a name, and a template reference.

Basic Item Creation

Example: Create an item by specifying template name.

$itemPath = "master:\content\home\Sample Item 3"
New-Item -Path $itemPath -ItemType "Sample/Sample Item"

Output:


Name                             Children Language Version Id                                     TemplateName
----                             -------- -------- ------- --                                     ------------
Sample Item 3                    False    en       1       {29A68114-5137-4A46-A87C-3789B8D898FB} Sample Item

The -ItemType parameter accepts either the template path (e.g., "Sample/Sample Item") or the template ID.

Example: Create an item using template ID.

$itemPath = "master:\content\home\Sample Item 4"
$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
New-Item -Path $itemPath -ItemType $templateId

Creating Items with Specific IDs

By default, Sitecore generates a new GUID for each item. Use -ForceId to specify a custom ID.

Example: Create an item with a predefined ID.

Output:

Creating Items as Children

Instead of specifying the full path, you can pass a parent item using the -Parent parameter.

Example: Create a child item under a parent.

Output:

Creating Items in Specific Languages

Use the -Language parameter to create items in specific language versions.

Example: Create an item with a specific language version.

Output:

When you specify a language during creation, only that language version is created. Other language versions are not automatically added.

Starting Workflows

Use the -StartWorkflow parameter to initiate the default workflow after item creation.

Example: Create an item and start its workflow.

Setting Field Values During Creation

After creating an item, you can immediately set field values.

Example: Create and populate an item.

Bulk Item Creation

Pattern: Create Items from CSV

Pattern: Create Items with Progress Reporting

Pattern: Create Hierarchical Structure

Pattern: Create Items from JSON

Removing Items

Use Remove-Item to delete items. By default, items are moved to the Recycle Bin unless you specify -Permanently.

Basic Item Removal

Example: Remove an item (sends to Recycle Bin).

Example: Remove an item permanently (bypasses Recycle Bin).

Removing Items via Pipeline

Example: Remove items from pipeline.

Example: Remove multiple items matching criteria.

Bulk Removal Patterns

Pattern: Remove Old Items

Pattern: Remove Items by Template

Pattern: Clean Up Empty Folders

Pattern: Remove with Confirmation

Pattern: Safe Removal with Reporting

Dynamic Parameters

Both New-Item and Remove-Item support dynamic parameters when working with Sitecore paths:

Parameter
Command
Description
Example

ForceId

New-Item

Forces specific GUID for new item

-ForceId "{GUID}"

Language

New-Item

Creates item in specific language

-Language "en-CA"

Parent

New-Item

Specifies parent item

-Parent $parentItem

StartWorkflow

New-Item

Initiates default workflow

-StartWorkflow

Permanently

Remove-Item

Bypasses Recycle Bin

-Permanently

FailSilently

Remove-Item

Suppresses errors

-FailSilently

Item Naming Considerations

When creating items, Sitecore applies item naming rules:

Valid Item Names

  • Alphanumeric characters (a-z, A-Z, 0-9)

  • Hyphens and underscores (-, _)

  • Spaces (converted to hyphens in URLs)

Invalid Characters

Sitecore automatically filters or replaces these characters:

  • Forward slash (/)

  • Backslash ()

  • Question mark (?)

  • Hash (#)

  • Colon (:)

  • Semicolon (;)

  • Brackets ([, ])

Example: Create items with special character handling.

Error Handling

Always handle potential errors when creating or removing items.

Pattern: Create with Error Handling

Pattern: Bulk Create with Error Logging

Performance Tips

  • Batch operations - Create or remove many items in a single script execution

  • Use BulkUpdateContext - When creating many items with field values

  • Use SecurityDisabler - If creating items programmatically (no user context needed)

  • Disable events - For large migrations where events aren't needed

  • Progress reporting - Always provide feedback for long-running operations

Example: Optimized bulk creation.

See Also

References

Last updated