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 ItemExample: Create an item using template ID.
$itemPath = "master:\content\home\Sample Item 4"
$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
New-Item -Path $itemPath -ItemType $templateIdCreating 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:
Using -ForceId with an existing ID will cause an error. Only use this when migrating content or when you need a specific ID for integration purposes.
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:
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).
Using -Permanently cannot be undone. Items are deleted from the database immediately. Use with extreme caution, especially in production environments.
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:
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
Retrieving Items - Find items to work with
Editing Items - Update item properties
Moving and Copying Items - Transfer items
Best Practices - Performance optimization
Appendix - Common Commands - Full cmdlet reference
References
Last updated