Tuesday, November 4, 2014

PowerShell Commands to Install, Update, Uninstall WSP Packages

Copy your WSP file to an appropriate location e.g.) C:\temp
Launch PowerShell on the SharePoint server Start -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell
Type Add-SPSolution c:\temp\TheSolution.wsp to add it to SharePoint
Install-SPSolution –Identity TheSolution.wsp –WebApplication http://www.anjansp.blogspot.com GACDeployment
The easiest option is to use GACDeployment as above. The DLL is installed in the Assembly folder on the server. If you want to use Code Access Security, replace -GACDeployment with -CASPolicies. At this point your solution is installed and will be available for use. If it is a web part, you should be able to see it at http://YourServer/_catalogs/wp/Forms/AllItems.aspx
At some point in the future you might wish to ugrade your solution. Generally it is safer to uninstall and re-install, but here is the command:
Update-SPSolution –Identity TheSolution.wsp –LiteralPath c:\temp\TheSolution.wsp –GACDeployment
To uninstall run this command:
Uninstall-SPSolution –Identity TheSolution.wsp –WebApplication http://YourServer
Followed by:
Remove-SPSolution –Identity TheSolution.wsp
Files can be removed from C:\temp after install.

To Remove completely 
Follow the steps for STSADM:
  1. Open command prompt and navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
  2. cd " C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN "
  3. Use the stsadm command = stsadm -o retractsolution -name solutionName.wsp -immediate
  4. and then remove the wsp = stsadm -o deletesolution -name solutionName.wsp
Follow the steps for Powershell:
  1. Go to All Programs => Microsoft SharePoint 2010 Products =>SharePoint 2010 Management Shell =>Run as administrator
  2. Uninstall-SPSolution -identity "solutionName.wsp"
  3. Remove-SPSolution -identity "solutionName.wsp"