Sitecore PowerShell Extensions

Couple of week ago I started study of Sitecore PowerShell and have learned some basic concepts of Sitecore PowerShell. Here I am writing those my learning of Sitecore PowerShell so maybe this will help you to understand Sitecore PowerShell.

What is Sitecore PowerShell?

Sitecore PowerShell is a module that allow user to access PowerShell (Console, Integrated Scripting Environment & plugs into various Sitecore pipelines) with in Sitecore Desktop environment. A powerful tool for the Sitecore admin & developer. Using Sitecore PowerShell user can do anything because it simply call Sitecore API to perform operation.

How to Install Sitecore PowerShell Extensions?

Download the Console installation package from Sitecore Marketplace.


Once you install downloaded package you will see a couple of additional icons in your Start menu. Sitecore Desktop Installation of Sitecore PowerShell Extensions successfully done.

In above screenshot start menu items highlighted in yellow these are the PowerShell Icons.

  1. PowerShell Console.

PowerShell Console

  1. PowerShell ISE

Sitecore PowerShell 03

User can perform scripting using PowerShell Console as well as PowerShell ISE.

Sample scripts

Working with pages

For the same of brevity I’m assuming your location is already somewhere within a Sitecore tree (e.g. you did something akin to cd master:\content prior to executing the following scripts.

List all properties & fields available for a particular page (including Sitecore properties defined in the item template).

get-childitem | get-member -memberType property*

List all items in the CMS of which template name contains “Article”

get-childitem -recurse `

| where-object { $_.TemplateName -match “Article” } `

| format-table DisplayName, Name, TemplateName

List all subitems and how many days ago were they modified

get-childitem -recurse `

| format-table -auto Name, `

@{Label=”Days since modified”; Expression={ `

[datetime]::Now.Subtract($_.__Updated).Days} }

Delete all pages that have not been modified for the last 365 days.

get-childitem -recurse `

| where-object {[datetime]::Now.Subtract($_.__Updated).Days -gt 365 } `

| remove-item

List all items Updated over the last 24 hours and who changed them.

get-childitem -recurse `

| where-object { $_.__Updated -gt [datetime]::Now.AddDays(-1) } `

| format-table -property DisplayName, “__Updated By”, {$_.Paths.Path}

List all pages that have their “Text” field filled in.

get-childitem -recurse `

| where-object { $_.Text -ne $null } `

| format-table -property DisplayName, {$_.Paths.Path}

Make a nice reviewer’s comment on all pages with their “Text” property filled in.

get-childitem -recurse `

| where-object { $_.Text -ne $null } `

| foreach-object { $_.ReviewersComment = “Great job providing content!” }

Add a warning to the beginning of “Text” property for all pages that have not been saved for the last 180 days.

get-childitem -recurse `

| where-object {`

[datetime]::Now.Subtract($_.__Updated).Days -ge 180 `

-and $_.Text -ne $null }

| foreach-object {$_.Text = “<p style=’color:red’>Old content. Review pending!</p>” + $_.Text }

Replace a string in a property on all pages with another string (in this sample – removing the warning the last sample added).

$old_content = “<p style=’color:red’>Old content. Review pending!</p>”

$new_content = “”;

get-childitem -recurse `

| where-object {$_.Text -match $old_content} `

| foreach-object {$_.Text = $_.Text.Replace($old_content, $new_content) }

Display the 10 most recently changed pages ordered in the reverse chronological order or changes. Display the page name, who changed it and when as well as the page status.

get-childitem -recurse `

| sort-object -property __Updated -descending `

| select-object -First 10 `

| format-table -property DisplayName, “__Updated By”, __Updated

Working with Media Library / files

Removes all .xml files from the “Old Xml Files” in Media library.

cd “master:\media library\Old Xml Files”

get-childitem -recurse `

| where-object { $_.Extension -match “xml” } `

| remove-item

Copy all files from the “staging” folder to the “production” folder in Media Library.

Copying files within media library is done as follows. This can also be done for items in the content branch.

copy-item “master:\media library\staging\*” “master:\media library\production\”

2 thoughts on “Sitecore PowerShell Extensions”

  1. Very good blog…please keep updating
    I want to learn Sitecore, but where to start ? I can’t even find the Sitecore software to learn. How do i learn Sitecore?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s