Microsoft .NET and SharePoint development

SharePoint solution deployment with PowerShell

As a developer I love to have everything automated and don’t like it too much to click around in SharePoint to deploy solutions, activate features or configure random stuff.

When developing SharePoint solutions we deliver WSP files and deployment instructions to the system engineers and they will deploy them to the different environments. But how great will it be to automate their work and deliver a single line deployment instruction like "Run this script!"? :-)

You can specify the name of WSP that’s currently installed and the name of the new WSP. This can be useful when you’re using version numbers in the WSP file names as you can see in the example script.

The script is fully configurable to your needs can perform the following actions:

  • Backup the currently installed solutions as WSP file
  • You can either choose to:
    • Uninstall (retract) and remove the solutions
    • Add the new solutions
    • Deploy the new solutions
  • Or:
    • Upgrade the installed solutions
  • Activate features on farm or web application level
  • Warmup the application pools after the deployment
  • Each step is logged in the PowerShell console

There’s also a method that will wait until the timer jobs (for retract, deployment and upgrade actions) are completed before processing the next action.

Each action can be used separately, just configure the boolean variables at the top of the script. Please note that you can’t use the upgrade actions when you also want to perform retract and/or remove actions.

# Set variables
$BackupSolutions = $true
$RemoveSolutions = $true
$AddSolutions = $true
$DeploySolutions = $true
$UpgradeSolutions = $false
$ActivateFeatures = $true
$WarmupWebApps = $true
$ConfirmDeleteSolution = $false
$ConfirmAddSolution = $false

$PortalURL = ""
$MySitesURL = ""

$WSPDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$BackupLocation = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
# Set the WSP names
$CoreWSPNameOld = "DevPoint.Intranet.Core.v1.wsp"
$CoreWSPNameNew = "DevPoint.Intranet.Core.v2.wsp"
$CoreWSP = Join-Path -Path $WSPDirectory -ChildPath $CoreWSPNameNew

$TimerJobsWSPNameOld = "DevPoint.Intranet.TimerJobs.v1.wsp"
$TimerJobsWSPNameNew = "DevPoint.Intranet.TimerJobs.v2.wsp"
$TimerJobsWSP = Join-Path -Path $WSPDirectory -ChildPath $TimerJobsWSPNameNew

Happy devving and deploying!

DevPoint-Solution-Deployment.ps1 (10.5KB)