Instead of writing a series of If statements you can use a Switch statement, which is equivalent to VBScript’s Select Case statement:

$page = Get-CurrentPage;
switch ($page.PageChildOrderRule) {
0 {"Undefined sort order. "}
1 {"Most recently created page will be first in list"}
2 {"Oldest created page will be first in list"}
3 {"Sorted alphabetical on name"}
4 {"Sorted on page index"}
5 {"Most recently changed page will be first in list"}
6 {"Sort on ranking, only supported by special controls"}
7 {"Oldest published page will be first in list"}
8 {"Most recently published page will be first in list"}
default {"No idea what that means!"}
}

Most of this is based on the Microsoft’s Windows PowerShell Quick Reference however despite the sharing scripting runtimes the nature of the both shells are pretty different (although the differences are not as vast as one might think).

Windows PowerShell

PowerShell Console for EPiServer

Interactive – command can ask for confirmations and can be aborted. User can be solicited to provide input.

Batch – all commands are being executed in one go, the script has no chance to ask questions, go or no-go decisions have to be solved within the script.

Supports colouring.

Supports plain text output only.

Supports command line arguments for running scripts.

All arguments are defined directly within the script or derived from context automatically.

Can access any file depending on the rights of the user.

Can only access files the web application identity can write to. Cannot access files on user’s machine but rather operates on the server’s file system. Cannot operate with elevated privileges.

That said, I considered that enough of the Reference document is irrelevant in the EPiServer scenario that it’s beneficial for the users of the console to have a bespoke cheat sheet created especially for the purpose of this plugin.

The content & samples of the original cheat sheet has been adjusted to more closely reflect scenarios usable for an EPiServer admin or developer.

Ok, so I’ve got my shot of endorphins writing about PowerShell last week (damn, it’s nice to be able to code again!), and I got pretty determined on making it usable and achieving all the goals I’ve initially envisioned. and in the process build a usable tool and a library of scripts that people can use either directly or to modify to meet their needs.

The goal for this week: Context Scripts

Context scripts are the first step to break the scripting out of the admin realm and into the editor’s space. Those scripts will still be written by admins and developers but the goal is for them to be usable by the authors. The goal for those scripts can be as trivial as e.g. syndicating all the great functionality little plugins like this Unpublish button by Ted in one place and then mix and match them to your liking.

Some of the important bits:

Context scripts are something that is visible to users on “Scripts” page.

Scripts can be exposed to everyone or just the groups of your liking… you define it in the script.

Scripts are grouped in collections that are defined in *.psepi files that you drop into your application folder