Showing external content with your Sitecore PowerShell scripts

Sitecore PowerShell Extensions have proven time and again as a great tool for manipulating and exposing Sitecore content, but that about if you need to show your authors something that is external to your Sitecore instance?

This blog shows a number of techniques to show pages and embedded content in various ways as part of your script execution.

Showing external content in a new tab

The most obvious way is to show your author an external page as a new tab in the browser. This can be achieved by executing a JavaScript expression that will become available in SPE 4.4+

Invoke-JavaScript -Script `
    "'', '_blank')"

But what if you want to present them with something that is more integrated with a Sitecore experience?

Opening external content within Sitecore Desktop window

How about opening the same URL but within the Sitecore desktop interface rather than in a tab? The following makes it possible:

$URL = ""
$Width = 800
$Height = 600
$Title = "Adam's blog..."

Invoke-ShellCommand `
    -Name "ise:iframe(spe_url=$url,spe_w=$width,spe_h=$height,spe_t=$title)" `
    -Path master:\ ` # not ideal but the cmdlet needs it

And will result in the following window appearing on your desktop:

But that is not the end, there are further ways to integrate external and internally crafted content in your SPE dialogs!

Show an IFrame in an interactive dialog

You can embed iframes within dialogues created with the Read-Variable cmdlet. The cmdlet is generally used to prompt your users to provide values for variables needed by your scripts, for this purpose it comes with a number of “editors”. one of such is “info” editor that does nothing more than rendering content of a variable or any data otherwise provided. Should the content be HTML formatted you can do some curious things with it, such as following:

$embed = '<iframe width="560" height="315" ' +
    'src="" ' +
    'frameborder="0" allowfullscreen></iframe>' 

Read-Variable `
    -Parameters @{Name="embed"; Title=""; Editor="info" } `
    -Width 595 -Height 410 `
    -Title "Cave Johnson on safe science" `
    -Description "Embedded Youtube video"

Resulting in the following dialog:


Iframe however is not the only thing you can embed, why not get a bit more creative and write the code in the dialog directly?

Consider this sample code:

$html = @'
 .banner { position: relative; overflow: auto; }
 .banner li { list-style: none; }
 .banner ul li { float: left; }
<script src=""></script>
<script src=""></script>
  $(function() {
<div class="banner">
	<li><img src=""></li>
	<li><img src=""></li>
	<li><img src=""></li>
Read-Variable `
    -Parameters @{Name="html"; Title=""; Editor="info" } `
    -Width 675 -Height 500 `
    -Title "Embedded carousel" `
    -Description "You can do just about anything!"

And the awesome result!


Hope this blog post will help you create even more awesome SPE interfaces.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s