Let's share the knowledge

reports

Sitecore Powershell Extension is a great tool/module developed by Adam Najmanowicz and Michael West that provides a command line and scripting environment for automating tasks.

In my previous blog post on Sitecore Powershell extensions, we learned very basics of this great module, like it’s introduction, how to install this module, and it’s features.

I would like to take another step in continuation of previous blog post, and like to show some features which can be leveraged out of it.

Retrieve Sitecore Item

We can fetch Sitecore Item based on ID or Path:

If we know the Sitecore item ID, it can be retrieved in following way:

We have to make sure that we are adding the context for database, in this case I have added “master”

If we know the Sitecore item path, it can be retrieved in following way:

Retrieve Items from all languages and versions

We just need to pass language and version parameter, if we want items based on specific language or version, we can specify that language and version as parameter values, instead of passing * to it.

Retrieve child Items

We can get all child items based on Sitecore path, this is how it can be used:

If you want to retrieve all descendants from the given path, we can add recurse parameter, please see following for ref:

Bulk Updates

There can be scenarios, where certain field(s) are not updated or empty for some reasons, and now you want to update that specific field for all the items, this is now not so easy, as you have several hundreds of items, but,there is an easy way to make this bulk update using powershell extensions.

In the above example- we are trying to filter all the child items under /content/helix/home node where “Browser Title” field is empty, once we have a list of all items, we are iterating over all such items and updating the field with the “Display Name” value of the item.

Bulk updates for “Alt” text

Another very valid scenario for bulk updates can be updating all the Image items where “Alt” text is missing, following can be used to update all such Image items:

In the above example- we have used Sitecore query to get all the items based on template name “Image” and then finding such items which has missing “Alt” text, once we have a list we just updated the “Alt” text with item display name value, and then it can be updated by content authors to put something more specific, if required.

I strongly encourage all Sitecore developers to start using this module, and see how this can be leveraged into your solution, this is for sure helping and going to help everyone a lot.

I will continue sharing my thoughts and experiences on this topic, please let me know if you have any questions.

Sitecore Powershell Extension is a great tool/module developed by Adam Najmanowicz and Michael West that provides a command line and scripting environment for automating tasks.

Sitecore Powershell Extensions works with Sitecore process, which can make native calls to Sitecore APIs and allows to change/update the Sitecore Items on the fly. The same Windows PowerShell syntax is used for running commands and writing scripts.

Installing Sitecore Powershell Extensions Module:

In order to Install SPE module, search for “powershell” in Sitecore marketplace- http://marketplace.sitecore.net/

Download and Install “Sitecore Powershell Extensions” module.

Once the module is installed, you have access to both console and ISE, see screen shot for ref:

There are several things which can be done using SPE module, which includes:

Getting Sitecore Item.

Getting child Items.

Get Item by path.

Get Items from all languages and versions.

Making bulk updates.

Publishing Sitecore Items.

Deleting Items based on specific conditions and

Several other features.

I just started using it, and the feature/benefits it provides is making me it’s addict.

In the next posts, i will be sharing my learning with the community, including some of the commonly used commands which can make developers life easy.

Thanks again to Michael West and Adam Najmanowicz for this wonderful module.