Code Snippet – Uninstall and Install SharePoint Solution Package

Code Snippet – Uninstall and Install SharePoint Solution Package
3 votes, 5.00 avg. rating (97% score)

Introduction

Quick snippet of power shell script how to uninstall and install a wsp in SharePoint 2013

Uninstall wsp / Install wsp


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
$SolutionPackageName = "MyWebStyles.wsp"
$solution = Get-SPSolution | where-object {$_.Name -eq $SolutionPackageName}
# check to see if solution package has been installed
if ($solution -ne $null) {
  # check to see if solution package is currently deployed
  if($solution.Deployed -eq $true){
    Uninstall-SPSolution -Identity $SolutionPackageName -Local -Confirm:$false
    Remove-SPSolution -Identity $SolutionPackageName -Confirm:$false
  }
}
Add-SPSolution -LiteralPath $SolutionPackagePath
Install-SPSolution -Identity $SolutionPackageName -Local -GACDeployment



Add a call to Get-SPSolution and conditional logic to determine whether the solution package is currently installed and deployed before attempting to retract or remove it.
Once solution is find, then call to Uninstall-SPSolution and Remove-SPSolution will remove solution package.Then use Add-SPSolution and Install-SPSolution to install the solution

January 19, 2014 В· Adi В· No Comments
Tags: , , , ,  В· Posted in: Packaging and Deployment, Powershell, Sharepoint 2010, SharePoint 2013

Leave a Reply

What is 9 + 3 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)