Imtech Run PowerShell Script Deployment Step

, , ,

In my previous article I wrote about extending the Visual Studio SharePoint development tools. Now it’s time for the first extension: Imtech Run PowerShell Script Deployment Step.

Deploying solutions using the Visual Studio SharePoint development tools

The new Visual Studio SharePoint development tools help you not only with creating solutions but also with deploying them to your SharePoint server. If you are new to the tools there is a whole section on MSDN dedicated to Packaging and Deploying SharePoint Solutions using the new tools.

The coolest thing about the Deployment Configurations is that they are fully customizable: not only you can define your own configurations, but you can also create custom Deployment Steps.

Executing PowerShell scripts in the Deployment process

Out of the box the Visual Studio SharePoint development tools ship with a number of Deployment Steps. These steps cover the most common tasks like recycling Application Pool, deploying Solutions and activating Features.

One of the new things in SharePoint 2010 is support for Windows PowerShell. You can use PowerShell to manage your SharePoint Farm but it can be also extremely useful also during the development process. Unfortunately, in the current release of the development tools, there is no support for executing PowerShell scripts as a part of the Deployment process.

Introducing: Imtech Run PowerShell Script Deployment Step

Imtech Run PowerShell Script Deployment Step is a custom extension for the Visual Studio SharePoint development tools. After installation it adds a new Deployment Step called Run PowerShell Script:

Run PowerShell Script Deployment Step in the Deployment Configuration dialog

In your Deployment Configuration you can select either one or multiple PowerShell Scripts to be executed during the deployment. Just pick a Run PowerShell Script task for every script that you want to execute.

Multiple Run PowerShell Script tasks selected in the Deployment Configuration

After you confirmed the Deployment Configuration, when you select the project in the Solution Explorer, you will see two new properties in the Properties Window: one for every PowerShell script you selected in the Deployment Configuration:

PowerShell Deployment Steps properties in the Properties Window

Using these properties you can define which PowerShell scripts should be run for every task.

Defining PowerShell scripts to run for every PowerShell Deployment Step

Important
The PowerShell script path that you enter in the Properties Window is not bound to a specific PowerShell Deployment Task. The number of the task that you see in the Properties Window simply says: “The first/second/third PowerShell script is…”. In order to change the order of the PowerShell scripts you have to change the value of the specific properties.

Finally when you choose Deploy from the Project menu, the Deployment Configuration will be executed and the PowerShell scripts, that you specified in the Properties Window will be run:

Result of running the Deployment Process with Run PowerShell Script tasks

Installing the Imtech Run PowerShell Script Deployment Step

Imtech Run PowerShell Script Deployment Step is available as a Visual Studio Extension. You can either download it from the Visual Studio Gallery or from your Visual Studio choose Tools > Extension Manager, and search for Imtech Run PowerShell Script Deployment Step:

Installing Imtech Run PowerShell Script Deployment Step using Visual Studio Extension Manager

Possibly related posts

13 Responses to “Imtech Run PowerShell Script Deployment Step”

  1. Jeremy Thake Says:

    That's awesome use of extending Visual Studio mate!

  2. Waldek Mastykarz Says:

    @Jeremy: Thanks! More about to come :D

  3. Make your own PowerShell scripts for SharePoint deployment in Visual Studio 2010 « The SI SharePoint Blog Says:

    [...] There is also a Visual Studio extension from IMTech that allows you to run a PowerShell script as a deployment step.  This is a good idea, and would [...]

  4. Enric Says:

    Hi Waldek, did you try to call a PS1 script file containing SharePoint cmdlets? When I use your extension with a PS1 that includes:

    Add-PSSnapin "Microsoft.SharePoint.PowerShell"

    I get the error:

    Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
    2.

    Should I load SharePoint cmdlets some other way?

  5. Waldek Mastykarz Says:

    @Enric: Are you running Visual Studio as administrator?

  6. Enric Says:

    Yes, I am running VS with "Run as administrator". And the same script works fine being executed from CMD (powershell .\xxxx.ps1).

  7. Waldek Mastykarz Says:

    @Enric: I've checked it for you and it turns out that this has to do with the fact, that Visual Studio is a 32-bit process, which cannot load the SharePoint PowerShell SnapIn which is 64-bit. As this Deployment Step is now a part of the CKS:DEV toolkit, I would like to ask you to file it as a bug in the Issue Tracker (http://cksdev.codeplex.com/workitem/list/basic) and we will try to get a solution for it as soon as possible.

  8. Waldek Mastykarz Says:

    @Enric: Just wanted to let you know that the issue has been fixed in CKS:DEV (http://cksdev.codeplex.com/SourceControl/changeset/changes/49691).

  9. Enric Says:

    Perfect! I'm downloading it right now.

    Thank you Waldek, great job!

  10. Waldek Mastykarz Says:

    @Enric: you're welcome :D

  11. Enric Says:

    Just one thing, Waldek: after executing the PS1 script, the Process object returns ExitCode = 0 even if a command has failed, so the generated StandardError text is lost (in fact, I could only see it debugging the code).

    if (cmd.ExitCode != 0)
    {
    logger.WriteLine(cmd.StandardError.ReadToEnd(), LogCategory.Error);
    }

    Do you think that the Standard Error could be always logged, regardless of the ExitCode?

  12. Waldek Mastykarz Says:

    @Enric: sure. I would appreciate it if you could add it to the Issue Tracker @ http://cksdev.codeplex.com so that we can note that, discuss with the team and if there is no blocks for it, include it in the next release.

    Thanks again for your feedback,

    Waldek

  13. Enric Says:

    You've got it!

    http://cksdev.codeplex.com/workitem/5214

Leave a Reply

Security Code:

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS
Copyright © 2007 - 2010 Waldek Mastykarz

Creative Commons License