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-Item .;
switch ($page.Language) {
"en" {"This version is in English"}
"pl" {"This version is in Polish"}
"tlh-KX" {"This version is in Klingon?!"}
default {"No idea what this language is!"}
}

I’m realizing time and time again that the learning curve for PowerShell can be steep without a proper guidance. While most people I talk to are very excited about the concept they become discouraged after a having some tries and not realizing its full potential. Therefore I decided it’s worth spending some time introducing some basic principles to help scripting alleviate some of the initial pains.

A great deal of this post is a port of my older post for similar console for EPiServer, but since the differences are significant enough to confuse Sitecore developers if I sent them to the original version, I’ve decided to create a proper Sitecore cheat sheet. 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 Sitecore

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 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 Sitecore 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 Sitecore admin or developer.

How to get help

Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.