Sitecore Development 101: The Ultimate Beginner’s Sitecore PowerShell Cheat Sheet
Everything you need to know to get started scripting in Sitecore
Start typing to search...
Sitecore PowerShell is a powerful scripting tool that offers Sitecore developers the flexibility to automate tasks, streamline content management, and perform administrative operations without needing to dive into the depths of the Sitecore API. For those new to Sitecore PowerShell Extensions (SPE), the syntax can seem a bit daunting at first, but with a basic understanding of the most common commands—getters, setters, and removers—you can start scripting efficiently in no time.
In this blog, we'll walk you through a beginner-friendly cheat sheet that outlines key commands to help you hit the ground running. Whether you're looking to retrieve items, update fields, or remove unnecessary content, this guide will provide you with a foundation to automate your Sitecore processes and make your daily development tasks easier. Let's dive into the core commands you'll need to start building powerful Sitecore scripts.
"Getters" in this context, are commands that allow you to retrieve or query information from the Sitecore database. They help you access items, fields, or properties without modifying them. These commands are essential for reading and analyzing Sitecore content before performing actions like updates or deletions.
Use this to retrieve a single item. Throws an error if the item does not exist.
## using a Sitecore ,[object Object],
$item = ,[object Object],-,[object Object], -,[object Object], ,[object Object],
,[object Object],
## using an Sitecore GUID
$item = ,[object Object],-,[object Object], -,[object Object], ,[object Object],
Use to return an item's children (without the -Recurse flag) and grandchildren (using the -Recurse flag).
[object Object],
,[object Object], = Get-ChildItem -Path ,[object Object], -Recurse
,[object Object],
,[object Object],
,[object Object], = Get-ChildItem -Path ,[object Object], -Recurse
Returns the layout for the specified item. Fields wrapped with [ ] are optional, remove before executing.
[object Object],
,[object Object], = Get-Layout -Item ,[object Object], [-Device ,[object Object],] [-FinalLayout] [-Language ,[object Object],]
,[object Object],
,[object Object],
,[object Object], = Get-Layout -Path ,[object Object], [-Device ,[object Object],] [-FinalLayout] [-Language ,[object Object],]
,[object Object],
,[object Object],
,[object Object], = Get-Layout -Id ,[object Object],[-Device ,[object Object],] [-FinalLayout] [-Language ,[object Object],]
Returns the layout for the specified device.
[object Object],
,[object Object], = Get-LayoutDevice -,[object Object], ,[object Object],
,[object Object],
,[object Object],
,[object Object], = Get-LayoutDevice -Default
Returns a RenderingDefinition for an item using the filtering parameters. Fields wrapped with [ ] are optional, remove before executing.
[object Object],
,[object Object], = Get-Rendering -Item ,[object Object], [-DataSource ,[object Object],] [-Rendering ,[object Object],] [-Index ,[object Object],] [-PlaceHolder ,[object Object],] [-Parameter ,[object Object],] [-Device ,[object Object],] [-FinalLayout] [-Language ,[object Object],]
,[object Object],
,[object Object],
,[object Object], = Get-Rendering -Path ,[object Object], [-DataSource ,[object Object],] [-Rendering ,[object Object],] [-Index ,[object Object],] [-PlaceHolder ,[object Object],] [-Parameter ,[object Object],] [-Device ,[object Object],] [-FinalLayout] [-Language ,[object Object],]
,[object Object],
,[object Object],
,[object Object], = Get-Rendering -Id ,[object Object], [-DataSource ,[object Object],] [-Rendering ,[object Object],] [-Index ,[object Object],] [-PlaceHolder ,[object Object],] [-Parameter ,[object Object],] [-Device ,[object Object],] [-FinalLayout] [-Language ,[object Object],]
Gets the available rendering parameters found for a given rendering. Fields wrapped with [ ] are optional, remove before executing.
[object Object],
,[object Object], = Get-RenderingParameter -Instance ,[object Object], [-,[object Object], <String[]>]
"Setters" are commands used to modify or update items and fields in the Sitecore database. They allow you to change the values of existing fields, update properties, or apply new settings to Sitecore items. Setters are essential for automating content updates and ensuring consistency across your Sitecore environment.
Editing an item can be done in three steps. Beginning the editing, making your desired changes and then ending the editing.
[object Object],
,[object Object],.Editing.BeginEdit()
,[object Object],.Fields[,[object Object],].Value = ,[object Object],
,[object Object],.Editing.EndEdit()
Sets an items layout for a device. Fields wrapped with [ ] are optional, remove before executing.
## ,[object Object], a Sitecore ,[object Object],
,[object Object],-Layout -,[object Object], $SitecoreItem -Device $DeviceItem [-Layout <,[object Object],>] [-FinalLayout] [-,[object Object], <,[object Object],[]>]
,[object Object],
## ,[object Object], a Sitecore ,[object Object],
,[object Object],-Layout -,[object Object], ,[object Object], -Device $DeviceItem [-Layout <,[object Object],>] [-FinalLayout] [-,[object Object], <,[object Object],[]>]
Updates rendering instance with new values. The instance should be earlier obtained using Get-Rendering. Fields wrapped with [ ] are optional, remove before executing.
[object Object],
Set-Rendering -Item ,[object Object], -Instance ,[object Object], [-Parameter ,[object Object],] [-PlaceHolder ,[object Object],] [-DataSource ,[object Object],] [-Index ,[object Object],] [-FinalLayout] [-Device ,[object Object],] [-Language ,[object Object],]
,[object Object],
,[object Object],
Set-Rendering -Path ,[object Object], -Instance ,[object Object], [-Parameter ,[object Object],] [-PlaceHolder ,[object Object],] [-DataSource ,[object Object],] [-Index ,[object Object],] [-FinalLayout] [-Device ,[object Object],] [-Language ,[object Object],]
,[object Object],
,[object Object],
Set-Rendering -Id ,[object Object], -Instance ,[object Object], [-Database ,[object Object],] [-Parameter ,[object Object],] [-PlaceHolder ,[object Object],] [-DataSource ,[object Object],] [-Index ,[object Object],] [-FinalLayout] [-Device ,[object Object],] [-Language ,[object Object],]
Adds and updates the specified rendering parameter from the rendering. Fields wrapped with [ ] are optional, remove before executing.
[object Object],-RenderingParameter -Instance ,[object Object], -,[object Object], ,[object Object], [-Overwrite]
"Removers" are commands that allow you to delete or remove items from the Sitecore database. These commands are useful for cleaning up unwanted or obsolete content. Removers help you automate content cleanup tasks while ensuring that your Sitecore environment stays organized and clutter-free.
Used to delete or recycle an item. Accepts items returned by Get-Item or Get-ChildItem.
## Passing the ,[object Object],-,[object Object], function directly into the ,[object Object], ,[object Object],
,[object Object],-,[object Object], -,[object Object], ,[object Object], | ,[object Object],-,[object Object],
,[object Object],
## Passing an already retrieved item into the ,[object Object], ,[object Object], function
$itemVariable | ,[object Object],-,[object Object],
Removes renderings from an item based on a number of qualifying criteria. The search criteria are cumulative and narrowing the search in an "AND" manner. Fields wrapped with [ ] are optional, remove before executing.
## ,[object Object], a Sitecore ,[object Object],
,[object Object],-Rendering -,[object Object], $SitecoreItem -Instance $SitecoreRenderingDefinition [-Device $DeviceItem] [-FinalLayout] [-,[object Object], <,[object Object],[]>]
,[object Object],
## ,[object Object], a Sitecore ,[object Object],
,[object Object],-Rendering -,[object Object], ,[object Object], -Instance $SitecoreRenderingDefinition [-Device $DeviceItem] [-FinalLayout] [-,[object Object], <,[object Object],[]>]
,[object Object],
## ,[object Object], a Sitecore GUID
,[object Object],-Rendering -Id ,[object Object], -Instance $SitecoreRenderingDefinition [-Device $DeviceItem] [-FinalLayout] [-,[object Object], <,[object Object],[]>]
Removes the specified rendering parameter from the rendering.
[object Object],
That’s it! That is everything one would need to know to do some basic level scripting. This blog covered the basics to simply get you started. For a fully detailed breakdown of all methods with all their optional parameters, please visit the official Sitecore PowerShell Extensions documentation here.
You can also check out my other blogs in the Sitecore Development 101 series:
Sitecore Development 101: Creating a Custom Rendering Contents Resolver
Sitecore Development 101: Creating an Interactive PowerShell Script