Thursday, July 5, 2012

Upgrade the SharePoint solution using PowerShell.


Hello today we will write the powershell script to upgrade the existing wsp to the sharepoint solution store.

1. Open any text editor.

2. Copy the below lines of script code inside it and save the file as like "Upgrade.ps1".

#************************************************************************************************************************
Write-Host ''
Write-Host 'Legal Intelligence deployment upgradation started.....' -foregroundcolor Cyan

# Ensure SharePoint cmdlets are loaded :
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Add-PsSnapin Microsoft.SharePoint.PowerShell
}

# Variables
$solutionNameCollection = @("Sharepointcustom.wsp")
$CurrentDir="D:\Solution Package"

# Upgrading the solution one by one
foreach ($solutionName in $solutionNameCollection)
{
Write-Host ''
Write-Host 'Starting upgradation of' $solutionName 'solution......' -foregroundcolor Cyan
$SolutionPath=$CurrentDir + "\" + $solutionName
Write-Host ''
Update-SPSolution -Identity $solutionName -LiteralPath $SolutionPath -GACDeployment -Local
Write-Host  'Completed upgradation of' $solutionName 'solution......' -foregroundcolor Cyan
Write-Host ''
}

Write-Host 'Upgradation completed.......' -foregroundcolor Cyan
Write-Host ''
Write-Host "Resetting IIS to clear application pools" -foregroundcolor Cyan
IISRESET
#************************************************************************************************************************

3. You need to change the current directory path of the wsp inside the script .For that find the "$CurrentDir" and replace it with your existing wsp path.
i.e. if you existing wsp is located to "D:\Solution Package" then value of the $CurrentDir is
$CurrentDir="D:\Solution Package"

4. Once the solution path will modified then change name of your wsp package.For that find the $solutionNameCollection value and replace it with your existing wsp name.
   i.e.if your wsp name is like "Sharepointcustom.wsp" then the value of $solutionNameCollection is
   $solutionNameCollection = @("Sharepointcustom.wsp")
   Note: if tou want to install the multiple wsp to the sharepoint solution store then seperate the wsp with comaa(,)
i.e. $solutionNameCollection = @("Sharepointcustom1.wsp","Sharepointcustom2.wsp","Sharepointcustom3.wsp")  

5. Save all the changes and open the "SharePoint Management Shell"  as an administrator mode from
   All Program -> Microsoft Sharepoint 2010 Products -> SharePoint Management Shell
 
6. Change the direcory path with the existing wsp path that you have already set the value of $CurrentDir="D:\Solution Package" in the script.
   From the powershell command propmt type the following command and press enter button.
   cd "D:\Solution Package"
 
7. Now type the following command and press enter.
   .\Upgrade.ps1
 
8. Likewise powershell script is used to upgrade the single or multiple wsp packages to the sharepoint solution store

Regards
Hiren Patel

No comments:

Post a Comment