Putting SPMS on ISE

2013w39-spms-20331-lab9-ex2

It’s a good thing that there is no stray “A” in the name SharePoint 2013 Management Shell, otherwise I would have to call it “SPAMS”, which would remind me of the old Monty Python sketch with the song refrain “lovely spam, wonderful spam”. For those of you who have a habit of pronouncing your four letter acronyms, I suppose you read the title of this as “putting spams on ice”? But I digress.

However “Putting the SharePoint Management Shell, which runs on the classic PowerShell.exe, onto the Windows PowerShell Integrated Scripting Environment (PowerShell_ISE.exe), so that we can use it more effectively” is a bit long and unwieldy for a title. Have you ever wondered how to put SPMS on ISE? Wonder no more; read on.

The default shortcut for the SharePoint 2013 Management Shell uses PowerShell.exe, however a few small changes can easily yield a SharePoint Management Shell based on the more awesomely powerful PowerShell ISE.

Step 1. Obtain the properties of the existing SharePoint 2013 Management Shell shortcut.

1.a) If you already have the SharePoint 2013 Management Shell shortcut on your Desktop, simply right-click on the shortcut and choose Properties, then move on to step 2. Otherwise, from the Start screen, use steps 1.b through 1.d.

1.b) Assuming that you are staring at the lovely SharePoint 2013 Management Shell tile on your Start screen, there are a few steps to obtain its properties. Start by right-clicking on the SharePoint 2013 Management Shell tile, and continue with steps 1.c through 1.d.

1.c) Note that the SharePoint 2013 Management Shell tile should now have a checkmark overlaid in the corner of the tile. In the Actions tool panel at the bottom of the Start screen, choose “Open file location”. This should show a Windows Explorer window in Desktop mode focused on the SharePoint 2013 Management Shell shortcut in the folder C:ProgramDataMicrosoftWindowsStart MenuProgramsMicrosoft SharePoint 2013 Products.

1.d) Right-click the SharePoint 2013 Management Shell shortcut in this folder and choose Properties.

Step 2. Select all the text in the Target field of the shortcut and Copy it (e.g. Ctrl+C), then Cancel the properties dialog. The text you copied should look like this:

C:WindowsSystem32WindowsPowerShellv1.0PowerShell.exe -NoExit ” & ‘ C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15CONFIGPOWERSHELLRegistrationsharepoint.ps1 ‘ ”

(Note: Don’t worry about the “v1.0” in the middle of the path to PowerShell.exe; that is normal for PowerShell versions 1.0, 2.0, 3.0, and 4.0.)

Step 3. Right-click on the Desktop (or other folder of your choice, such as the ProgramData…Start Menu folder) and choose New > Shortcut.

Step 4. In the Create Shortcut dialog’s “Type the location of the item” text box, Paste the text from the old shortcut into the new one, and before hitting the Next button, Edit the new shortcut’s path as follows.

To change this to use the PowerShell_ISE.exe, we can perform the following edits:
Change the command name to PowerShell_ISE.exe
Remove the -NoExit option, as this is not relevant to the ISE.
Remove the ampersand (&).
Remove both of the apostrophes (‘), but keep the quotation marks (“). Note, it is also advisable to eradicate some of the extra spaces around those apostrophes, yet be careful to retain at least one space before the opening quotation mark (after the PowerShell_ISE.exe part).

The result should look like this:
C:WindowsSystem32WindowsPowerShellv1.0PowerShell_ISE.exe “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15CONFIGPOWERSHELLRegistrationsharepoint.ps1”

Step 5. Now hit the Next button in the Create Shortcut wizard. On the “What would you like to name the shortcut?” / “Type a name for this shortcut” step, change the name “powershell_ise.exe” to something more administrator-friendly and functionally descriptive, such as “SharePoint 2013 on ISE” or “SharePoint 2013 Management ISE”. Then, hit the Finish button to finish creating the new shortcut.

That’s it. Note that when you open this shortcut, it shows the “sharepoint.ps1” script in the script editor pane of the PowerShell ISE, but does not actually run it. You can run it by typing <F5> on the keyboard, pressing the “play” (green triangle) icon titled “Run Script (F5)” in the ISE toolbar, or choosing either File > Run or Debug > Run/Continue from the menus.

Here is the contents of that script (sans signature block):
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = “ReuseThread” }
Add-PSSnapin Microsoft.SharePoint.PowerShell
Set-location $home

Two side notes:
You could easily include this script in a PowerShell profile script (e.g. profile.ps1, Microsoft.PowerShellISE_profile.ps1, etc.) so that you don’t need to explicitly run it every time you launch a new SharePoint 2013 on ISE session.
From the Start screen, right-clicking on either the original “SharePoint 2013 Management Shell” tile or the new “SharePoint 2013 Management ISE” tile and choosing “Pin to taskbar” from the Start screen Actions tool panel is a great way to make these shortcuts available in Desktop mode.

Now, back to our story about the SharePoint 2013 Management ISE. The critical line of that script, namely: Add-PSSnapin Microsoft.SharePoint.PowerShell simply imports many cmdlets for management SharePoint Server 2013 farms. Once those cmdlets have been imported, try each of the following.

(a) At the shell prompt, type:
Get-Command -Module Microsoft.SharePoint.PowerShell

(b) Hit the Refresh button in the ISE Commands panel, then in the Modules menu choose “Microsoft.SharePoint.PowerShell”. Note, both the Modules menu and Refresh button are at the top of the Commands panel (use View > Show Command Add-on if that panel is not visible).

These cmdlets for managing SharePoint 2013 environments are immensely powerful, yet hopefully the ability to use them within the Integrated Scripting Environment instead of just that classic PowerShell interface is helpful for both interactive management and composing SharePoint management scripts.

NOTE: An edited version of this article was posted on January 7, 2014 to the Global Knowledge Training Blog at <http://blog.globalknowledge.com/technology/microsoft/putting-the-sharepoint-management-shell-on-ise/>