Putting the SharePoint Management Shell on ISE

powershell100452449I wanted to title this “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,” but that’s a bit long and unwieldy and would never get past a blog editor.

The extremely short version I tried, “Putting SPMS on ISE,” wouldn’t work either, since “SPMS” is only an “A” away from “SPAMS,” which would lead us to the Monty Python tune “…lovely SPAM, wonderful SPAM,” which is way, way off course.

So… have you ever wondered how to put SharePoint Management Shell onto the Windows PowerShell Integrated Scripting Environment (ISE)? 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.

1a. 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 1b through 1d.

1b. 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 1c and 1d.

1c. 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:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft SharePoint 2013 Products.

1d. 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), and then Cancel the properties dialog. The text you copied should look like this:

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -NoExit ” & ’
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\CONFIG\POWERSHELL\Registration\\sharepoint.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. 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, but 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:\Windows\System32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
“C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\15\CONFIG\POWERSHELL\Registration\\sharepoint.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 content 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:

  1. 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.
  2. 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 (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:

  1. At the shell prompt, type: Get-Command -Module Microsoft.SharePoint.PowerShell
  2. Hit the Refresh button in the ISE Commands panel, and 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. I hope you’ll find the ability to use them within the ISE instead of just that classic PowerShell interface is helpful for both interactive management and composing SharePoint management scripts.

Related Courses
Core Solutions of Microsoft SharePoint Server 2013 (M20331)
Advanced Solutions of Microsoft SharePoint Server 2013 (M20332)
Automating Administration with Windows PowerShell v3.0 (M10961)

Please support our Sponsors here :