Unicorn 4 will feature full support for Sitecore PowerShell Extensions (SPE) to perform Unicorn actions. If you’ve ever wanted deep programmatic control over Unicorn (for example “I want to sync Foundation.*”), or if you’ve got an existing deployment process that’s already using SPE Remoting to perform deployment tasks - this is for you.
To use Unicorn cmdlets in SPE, all that is necessary is to install the SPE package along with Unicorn. Unicorn 4 comes with configuration that remains quiescent until SPE is installed that will automatically enable the Unicorn cmdlets. In case that’s not clear enough: SPE is an optional addition and will not be required to use Unicorn 4.
So what can we do with Unicorn cmdlets for SPE?
Configurations
1 | # Get one |
The result of Get-UnicornConfiguration
is an array of IConfiguration
objects, which you can spelunk (e.g. with their Name
property) or pass to other cmdlets. Configurations are read only.
Syncing
Sync cmdlets make use of Write-Progress to provide a similar progress bar experience to the Control Panel, albeit a bit less responsive.
1 | # Sync one |
For example:
Partial Syncing
Sometimes you want to only sync a portion of a configuration. You can do that with PowerShell using Sync-UnicornItem
.
1 | # Sync a single item (note: must be under Unicorn control) |
Reserializing
The cmdlet to reserialize is called Export-UnicornConfiguration
because Reserialize
is not an approved verb for a cmdlet :)
1 | # Reserialize one |
Partial Reserializing
Sometimes you want to only reserialize a portion of a configuration. You can do that with PowerShell using Export-UnicornItem
.
1 | # Reserialize a single item (note: must be under Unicorn control) |
Converting to Raw YAML
You can also dump out the raw YAML for an item - or items. The output of ConvertTo-RainbowYaml
is either a string or array of strings depending on how many items were passed to it. Note that unless -Raw
is specified, the default field formatters and excluded fields Unicorn ships with are used. These are non-customizable and do not follow Unicorn defaults if changed.
This capability enables casual use of YAML serialization without having to use Unicorn or set up a configuration. It’s not a good solution for general purpose synchronization though simply because the nuances of storing trees of items in files are many. Very many. But I’m curious what uses people will find for this :)
1 | # Convert an item to YAML format (always uses default excludes and field formatters) |
Converting from Raw YAML
In Rainbow the IItemData
interface is the internal unit of an Item. The ConvertFrom-RainbowYaml
cmdlet converts raw YAML string(s) into IItemData
which you can then spelunk as objects or deserialize as needed.
1 | # Get IItemDatas from YAML variable |
Deserialization
To deserialize items, use Import-RainbowItem
which takes IItemData
items in and deserializes them into the Sitecore database. No comparison is done before deserialization, which makes this a bit slower than a full Unicorn sync.
As a shorthand Import-RainbowItem
also accepts YAML strings, however as IItemData
can represent any sort of item, it is not limited only to deserializing YAML-sourced items.
1 | # Deserialize IItemDatas from ConvertFrom-RainbowYaml |
Questions?
Does this mean the existing PowerShell Remote API is obsolete?
No. The existing PowerShell API uses Windows PowerShell to provide remote syncing capability and does not require installing Sitecore PowerShell. They serve different parallel purposes, and both are here to stay.
You have no gifs or memes in this post. Is something wrong?
Can I have a beta yet?
I’ll be releasing a beta once I finish the features I have planned. Yep, there’s at least one more ;)