Sitecore Powershell Extensions Plugins

Reading time ~1 minute

Sitecore Powershell Extensions is a great module which improves your productivity significantly. Easy extensibility via integration points is only one of many advantages which comes with SPE1. Read more to see how you can bring those opportunities into play.

I am spending a lot of time inside ISE and I realized that some of my recurring actions could be optimized.

The one thing I was doing very often is item serialization. Navigating through the whole tree to find the exact script item is really annoying. That was an impulse for me to improve my workflow a bit.

Enhancing PowerShell ISE

With SPE1 you can easily write your own plugins, which is really great! See some examples below.

Serialize button

The goal is to create plugin which will serialize currently opened script.

  1. Create your own Module with ISE Plugins integration point checked,
  2. Navigate to your module and find ISE Plugins node,
  3. Create new script beneath that node,
  4. Fill the script content with following piece of code,
1
2
3
4
5
6
if ([string]::IsNullOrWhiteSpace($scriptItem)) {
	Show-Alert "Script item is empty"
	exit
}

Serialize-Item -Item $scriptItem

Reload ISE and have fun with new functionality. Now you don’t have to dig into the tree to find script item.

Pro-tip: If you cannot see your plugins in ISE make sure you have enabled your module.

As you can see it is pretty easy to do something helpful in few seconds. If you are going to write something by your own here is a list of variables to which you can get access to in plugin context:

1
2
3
$scriptText
$selectionText
$scriptItem

Open script item in Content Editor

Although it is very easy to add button with single action you might want to navigate to the item anyway. I’ve got simple solution for that as well. Use following code snippet:

1
2
3
4
5
6
7
if ([string]::IsNullOrWhiteSpace($scriptItem)) {
	Show-Alert "Script item is empty."
	exit
}
Show-Application `
 	-Application "Content Editor" `
 	-Parameter @{ id = "$($scriptItem.ID)"; fo = "$($scriptItem.ID)"; la = "$($scriptItem.Language.Name)"; vs = "$($scriptItem.Version.Number)"; sc_content = "$($scriptItem.Database.Name)" } 

See how it looks in action:

Summmary

Plugins are just one of the possible integration points in SPE1. I highly recommend you to familiarize with all. I am pretty sure you could solve some of your problems and make live easier.

SXA Extensions - Multisite Management

Easily remove tenant groups, tenants, site groups, sites with context menu scripts. Continue reading

SXA Toolbox - Search Box

Published on May 08, 2017