Using SharePoint Powershell from PowerShell ISE

Whoever has worked with PowerShell probably came to the same conclusion: this stuff is potent and powerful!

The ‘standard’ SharePoint 2010 Management Shell does have some drawbacks.

Working with a Command-Prompt-like environment does not appeal to everyone, especially those used to visual IDE’s like Visual Studio. Fortunately, PowerShell v2 comes with PowerShell ISE, a more visual experience that makes it much easier to work with scripts. This is available by default on Windows 7 and can be enabled as a feature on Windows Server 2008, using the following PowerShell command:

Add-WindowsFeature PowerShell-ISE

You can now find PowerShell ISE shortcuts in the Start Menu.

However, when you start PowerShell ISE, you’ll find that it only works with Windows cmdlets. For PowerShell ISE to work with SharePoint cmdlets, you’ll only need to add a PowerShell Snapin, using the following command.

Add-PSSnapin Microsoft.SharePoint.PowerShell

After this, you’ll be able to access the SharePoint commandlets, whose noun all start with “sp”.

Now if you’re like me, you’ll always want these SharePoint cmdlets available from PowerShell ISE. Zubair Alexander posted a way of doing this earlier this year on his blog.

  1. You can check if a PowerShell profile is available for your current identity using the Test-Path $profile command. This will return true if a profile is present and false if not.
  2. You can create a new profile for your identity by using the following command:
    Test-Path $profile
    if (!(test-path $profile)) {new-item -type file -path $profile -force}

    This will perform a “Create Directory” operation on the target destination folder C:\Users\<username>\Documents\WindowsPowerShell, and add a file titled “Microsoft.PowerShellISE_profile.ps1″ to this folder.

  3. Now, use PowerShell ISE to open the newly created .ps1 file
  4. Add the command
    Add-PSSnapIn Microsoft.SharePoint.PowerShell

    (and any other commands you want to automatically run when you open PowerShell ISE) to the file and press Save.

  5. Restart PowerShell ISE. You’ll now find you’ll be able to access all SharePoint cmdlets directly, each time you run PowerShell ISE on this machine.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>