Using Unicorn and a Text Editor to do Bulk Updates in Sitecore

Posted 07/18/2016 by Ed Kapuscinski

I know this is a little low-brow way to do things, but it's a technique I've found useful numerous times while doing Sitecore Habitat development. 

There are often times when I need to update a bunch of values in content items in the same way. The example in this case was removing a "preset" value that wasn't applicable in my project. 

Because Habitat projects use Unicorn to serialize items, and that serialization is always up to date, you can use a text editor of your choice to manipulate Sitecore content and easily update the CMS with those updates.

Using Unicorn For Bulk Replacements In Sitecore

In my example, I needed to remove the {2A507E75-D068-4618-9F98-5C3A1D6D3A01} preset from every data template in my project. Yes, I could've gone through each one and manually done it, but as I've previously established, I'm a lazy developer. 

I could also do the same thing with a powershell script, but, again, see above about being lazy. This approach let me use a tool that was already open in my development environment to do a simple text update.

The first step was identifying what text needed to change. In my case, it was just removing the GUID "{2A507E75-D068-4618-9F98-5C3A1D6D3A01}" from a field. Using the "raw values" view can be helpful in figuring this out.

Once I knew what find and replace I needed to do, it was a simple issue of firing up my favorite text editor, Notepad++. 

I used the "Find in Files" utility to look for every instance of the text I needed removed in the "serialization" folder of the project. This scope could be expanded as necessary, if you need to cast a wider net. I told it to replace "{2A507E75-D068-4618-9F98-5C3A1D6D3A01}" with nothing, and ran "Find All" to be sure I had things right. 

Using Find and Replace in Notepad++

When the results list looked right, I told it to "Replace in Files". 

That told it to look through all those easy to read .yml files in the serialization folder, and update them accordingly.

It was then a simple matter of running a Unicorn Sync of the affected project to push my altered values back into the CMS. This was done by going to /unicorn.aspx on my site, going to the project, and telling it to sync.