PowerShell as any other scripting language is very useful for DevOps tasks to automate repetitive operations. Sitecore solutions are no exception to these scenarios and using Sitecore PowerShell can increase productivity in daily basis content management tasks.

Sitecore PowerShell Extensions (SPE) is a popular and well documented Sitecore module. It’s been around since Sitecore 6.4 and it’s being kept up to date with new features over time. It provides a set of commands that follows Windows PowerShell syntax (Verb-Noun) and use the Sitecore native API to perform operations such as getting or editing Sitecore items. Additionally, it’s a prerequisite for configuring the Sitecore Experience Accelerator in Azure (https://doc.sitecore.net/sitecore_experience_accelerator/13/setting_up_and_configuring/setting_up/configure_sxa_for_deployment_on_the_azure_app_service).

How to start?

  1. Make sure the following prerequisites are in place: https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/installation.html#prerequisites
  2. Download from the Marketplace (https://marketplace.sitecore.net/en/Modules/Sitecore_PowerShell_console.aspx) the latest version of the module that matches your Sitecore. Use the Compatibility table as reference: https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/appendix.html#compatibility-table. If you are planning to work with SXA check this compatibility table: https://doc.sitecore.net/sitecore_experience_accelerator/13/setting_up_and_configuring/setting_up/configure_sxa_for_deployment_on_the_azure_app_service. The module is installed as any other Sitecore package using the Installation Wizard.
  3. Get familiarize with the basic features it provides:
    • PowerShell Console, accessible in Sitecore Desktop (Start -> PowerShell Console) and in the Content Editor, through the menu in context that appears when you right click an item in the Sitecore Tree.
    • PowerShell Scripting Environment (ISE), accessible in the Sitecore Launchpad.
  4. Check the glossary of commands of the official documentation: https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/appendix.html#commands.

Script structure for working with items

In the project I am currently involved there’s a need to modify data over a large set of similar items (same template). After creating several scripts, there’s a structural pattern that can be identified:

  1. Parameters section. Statement to receive and validate the scripts parameters. The goal is to create generic and reusable scripts.
  2. Query section. Section to retrieve the set of items to work with. A way to do it is with the Get-Item with -Query option to use a Sitecore query. Consider that it depends on the Query.MaxItems which by default is 100 (the Sitecore.ExperienceExplorer.config sets it to 260). You can explore the command Get-ChildItem instead.
  3. Iterative section. Section where the specific action is done to each one of the items retrieved from the previous step.

The following script gives an example of this (get it raw from here: https://raw.githubusercontent.com/josepavi86/sc-powershell-scripts/master/Set-ItemProps.ps1). It receives the path in the Sitecore Tree, the Template Id to restrict the query and the set of fields and values to apply to each one of the retrieved items.


# PS Script that sets the value of a list of fields
# Example of how to call this script
# $argumentList = @{'path'='/sitecore/content/home'
#                ; 'templateId'='{AB59F27A-8CC9-4AE6-B9A9-DE649A94691F}'
#                ; 'templateAttr'= @{'Field1' = 'Text value'
#                            ; 'Field2' = '1'
#                            ; 'Field3' = '{DADA3C82-7AA6-4265-951C-CAF63FBE17D3}'}};
# Invoke-Script 'SampleScriptsSet-ItemProps' -ArgumentList $argumentList | Out-File C:ScriptsSet-ItemProps.log

# -------------------------- PARAMS SECTION ------------------------
$path = $($params.path);
$templateAttr = $($params.templateAttr);
$templateId = $($params.templateId);

if ($path -eq $null -or $path -eq '') {
    "'path' parameter is required";

if ($templateAttr -eq $null) {
    "'templateAttr' parameter is required";

if ($templateId -ne $null -and $templateId -ne '') {
    $queryPath = "$path/*[@@templateid='$templateId']";
} else {
    $queryPath = "$path/*";

$count = 0;
# -------------------------- QUERY SECTION --------------------------
# Get-Item using -query option depends on the value of Query.MaxItems setting
# It's 100 by default and the Sitecore.ExperienceExplorer.config sets it
# to 260. You can explore the command Get-ChildItem instead.
foreach($item in Get-Item -Path master: -Query $queryPath) {

# -------------------------- ITERATIVE SECTION ----------------------

    $templateAttr.GetEnumerator() | ForEach-Object {
        $item[$_.Name] = $_.Value;

    $item.Editing.EndEdit() | Out-Null;
    Write-Output "Item '$($item.ItemPath)' - DONE";

 Write-Output "Total processed items: '$count'";

José Pablo Villalobos

Technical Architect in POSSIBLE with 5 years of experience building Sitecore solutions and 10 years as a software developer. Passionate about delivering user-centered solutions and trying new technologies.

All author posts