Thursday 9 February 2012

Update-SPSolution Automated Install

Just a quick script drop, I am going to polish this up a bit over the coming weeks.  This script will Update all of the WSP’s in the install folder. It will not add new solutions only update old ones.  How it works:
  1. Create the following folder structure (where OutofBand is the name of your release):


  2. Drop your wsps you want to release in the install folder
  3. Drop your current production wsps in the rollback folder (if you do not have them check this out)
  4. Create setup.ps1 in the OutofBand folder with the following code
  5. Do not run this from PowerShell ISE, the Get-Location will fail.  This will cause an IISReset

  6. #Release Script for SharePoint 2010 wsps (assumes wsps have already been released)
    asnp Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

    [string]$strDeploymentFiles = Get-Location -PSProvider FileSystem;
    [bool]$Rollback = $false;

    if ($Rollback)
    {$strDeploymentFiles += "\rollback\";}
    else
    {$strDeploymentFiles += "\install\";}

    $strd = dir -Recurse $strDeploymentFiles *.wsp;
    foreach($wsp in $strd)
    {
        [string]$strWSPName = $wsp  
        Update-SPSolution -Identity $strWSPName -LiteralPath "$strDeploymentFiles$wsp" -Force -GAC
    }


  7. To deploy your solution files simply run setup.ps1 from SharePoint 2010 Management Shell
  8. If you need to roll back update the $Rollback variable to $true