Monday, July 13, 2015

Sitecore PowerShell Extensions Remoting v2

Let me start off by saying that the work done by Himadri here is a great example at the flexibility of SPE. Not long ago Adam posted about Remoting in SPE, it became clear that we needed to have a Windows PowerShell module that users can setup outside of Sitecore that would come with all the necessary commands to interact with SPE. In our 3.1 release we included the module, so feel free to grab that now.

In this post I would like to show some recent enhancements made in 3.2 that will make interacting with SPE even better!

The packaged Windows PowerShell module can be found on the marketplace listed as SPE Remoting. That is the preferred method for interacting with SPE outside of the Sitecore environment. If you wish to use the same code from within the browser, such as to interact with another instance of SPE, you'll find the commands under here:
master:/system/Modules/PowerShell/Script Library/Platform/Functions/Remoting2

We've included all of the documentation below in our book.
When you execute the script or import the module you'll get the following commands:
  • New-ScriptSession - This can be reused between calls to all the other commands.
  • Invoke-RemoteScript - Best option for performing any remote script execution.
  • Send-MediaItem - Remotely upload.
  • Receive-MediaItem - Remotely download.
Let's walk through a few examples at using the commands.

Create a new session object that will contain a reference to the SPE session id and the web service proxy. Next we invoke a scriptblock on the server within the session.

If you would like to download images from the media library you can do something as simple as the following:

If you would like to upload images from the filesystem to the media library you can do something like this:

Saturday, May 16, 2015

Sitecore PowerShell Extensions - System Maintenance

Here recently I was thinking about how I could perform some of the system maintenance tasks that you would have to manually run from the Sitecore Control Panel. I decided to add these scripts to the System Maintenance script module in the Sitecore PowerShell Extensions module. I hope this encourages you to spend a little more time in SPE.

// michael

Friday, April 10, 2015

Sitecore PowerShell Extensions Tip - Count Items

Today I needed a quick report to find out the number of "pages" on our site. I came up with a quick estimate using the Sitecore PowerShell Extensions module.

I hope this encourages you to spend a little more time in SPE.

// michael

Thursday, February 26, 2015

Move Workstation To New OU With PowerShell

Question came up at work today on how to move a workstation in Active Directory from one OU to another. Here's what I came up with.

I hope this helps someone!

Import-Module ActiveDirectory

$computers = "PC1","PC2" # Optionally use Get-Content -Path C:\computers.txt
$computers | ForEach-Object { 
        $computer = "$($_)$"; Get-ADComputer -Filter { SamAccountName -eq $computer } | 
        Move-ADObject -TargetPath "OU=Retired Workstations,OU=Company,DC=company,DC=corp"

// michael

Tuesday, January 20, 2015

Sitecore Code Editor 1.6 Preview

Developing on the Sitecore platform has been some of the most enjoyable time in my career. For me, the excitement of discovering new aspects of  the platform and building features for a module that I'm going to just give away is well worth the late night investment. I hope those of you that use the module find it helpful. Enjoy!

Today I would like to outline the changes included in v1.6 of the Sitecore Code Editor Module. Those of you that have never seen or heard of this module, it provides an improved text editing experience using the Ace Code Editor plugin. I'll outline some of the enhancements or fixes then go through each in greater detail.


  • Added persistent user settings for the editor.
  • Added configurable height and width for the editor window.
  • Added scrolling to the content editor window.
  • Updated with new mimetypes.
  • Fixed issue with media blobs not appearing in module packages.
  • Fixed code template share setting.
The nice thing about this release is it was heavily influenced by community requests. You may have noticed while using the code editor on most computer screens the modal window was just not quite large enough. Now the module supports storing the modal window width, height. In addition, settings that effect the text include font size, font type, and theme. 

The content window in the Content Editor now supports scrolling for large sets of text.

Mime types have been added for files with content for LESS, SCSS, Windows PowerShell, and others. These can be found in Sitecore.SharedSource.CodeEditor.config.

The Code Attachment field type was removed to correct an issue where media item blobs were not properly included in the packages. I figured out that I can add command buttons in the content editor in code rather than defining in the core database as a new field type. Thanks to John West for posting that article a few years ago :)

I've reverted back to the original Attachment system type but changed the control.

Some cleanup is required, more specificly the Code Attachment field type.

That's pretty much it. Happy coding!

// Mikey