Sitecore PowerShell scripts for better productivity

Pranay    05 Apr '19    417 views

Here is a list of Sitecore PowerShell scripts that are useful for every Sitecore developer for making any bulk changes in Sitecore.

As the size of the Sitecore instance increases the maintenance of the Sites would become challenging and it brings the need for a scripting tool to make bulk actions on Sitecore items. Here is a list of such scripts which would do bulk activities like checking fallback, remove/updating workflows, organising the media items etc. Il try my best to add more to this list.

Image Text

1. Sitecore PowerShell script to enable Language fallback

There may be a situation where you would like to make sure the language fallback is enabled on all your Sitecore items or a particular sub tree. Checking all the items manually is not a feasible task. In such cases this script can help to check if the language fallback is enabled and if required this script can enable the fallback setting and publish the item automatically in minutes/hours based on your instance size.

2. Sitecore PowerShell script to remove all language versions except one

For some reason you might want to remove all the language version except English or any other language. This would be tedious task to remove all language version even for one item as it requires to switching the language one by one and removing the versions. If there are multiple items, then it would be more challenging. So here is a script which can remove all the versions except one (either 'EN' or can be configured) for an item and its children recursively.

3. Sitecore PowerShell script to remove/update workflows

You might want to check if the right workflow is assigned to all of your items or you may have created a new workflow and like to assign this to all of your items in Sitecore or you simply want to remove the workflow of all your items. In any of these cases, you should be updating the workflow fields of each and every item in Sitecore. This is where this script can be used. This script can update the workflow field and workflow state field with a specific condition for all items or update only when there is a specific value conditionally.

4. Sitecore PowerShell script to get unreferenced media items

As your Sitecore instance gets older there could be more and more media items get added to the Sitecore media library. In the long term this impacts the size of Sitecore databases. Also, it could have a performance impact. It is always required to do some basic maintenance like removing/deleting the media items that are not used since a long time. This script gets the list of all unused/unreferenced media items from the media library.

5. Sitecore powershell script to move media items based on references

This powershell script would be really interesting. Say there are multiple websites in your Sitecore. All the media items for these Sites are unorganised and your content authors may place the images in one common folder, then it would be difficult to understand which images are being used in which website. So to solve this, we can take each image and check their references, based on the references it can be understood which site node is using this image. Now we can create a new folder inside the media library for this particular site and place this image in that folder. Like this we can check each of the media items inside the media library and move to the appropriate folder. If a media item is being used in multiple site nodes, then we can place this in a common folder. All these cannot be done manually and hence this script would be really helpful.

I try my best to keep this list updated. Hope you find these scripts helpful. Please comment your thoughts.

About the author

Pranay Deegoju
Sitecore Certified Professional

A Software Engineer by profession, a part time blogger and an enthusiast programmer. You can find more about me here.



Leave your comments on this post here


Want more such posts, subscribe here

Recent Posts

×

Liked this article?

Subscribe with your email and get updates when ever a new article is posted.

By subscribing you agree to our privacy terms. We promise that we do not sell your data.