Kirk Evans Blog

.NET From a Markup Perspective

Extract a WSP Solution from SharePoint 2010

Extract a WSP Solution from SharePoint 2010

Rate This
  • Comments 9

This post shows how to download a WSP from SharePoint 2010 using PowerShell.

Background

A customer of mine had a scenario where they needed to download a WSP from SharePoint 2010.  In the Central Administration screen, a link is not available for you to download the WSP solution.

image

Likewise, with stsadm, there’s not a command to download a solution. 

Implementation

I could have written this with a C# console application, but I’ve been playing with PowerShell and found that the 3 lines of PowerShell code that it takes is much easier than trying to deploy a binary to a customer’s environment. 

$farm = Get-SPFarm
$file = $farm.Solutions.Item("extendeddiagnosticproviders.wsp").SolutionFile
$file.SaveAs("c:\temp\extendeddiagnosticproviders.wsp")

Note that in order to run this command, you need to be a member of the Farm Administrators group and have permission to the configuration database.  To configure the permissions for SQL, I recommend using Add-SPShellAdmin.

For More Information

SPSolutionCollection

SPSolution class

Add-SPShellAdmin

  • Hi...thanks for post...Will this same command work for Sandbox solutions too. Just curious, i know we can download sandbox solutions from site.

  • Nice catch.  For Sandbox solutions, this would not work because this solution accesses items in the SPFarm.Solutions collection, the solutions are stored in the farm as part of the configuration database.  Sandbox solutions are different because they are stored in the content database, in a document library called the Solution Gallery.  If you want to access these programmatically, I would think you could use the SPList API, or Lists.asmx web service.

  • Helped us out of a pinch! Thank you!

  • After run third command facing below error :

    You cannot call a method on a null-valued expression.

    At line:1 char:1

    + $file.SaveAs("d:\backup\GIB_Extenstion.wsp")

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

       + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

       + FullyQualifiedErrorId : InvokeMethodOnNull

  • Kirk, you saved my day

    you are my hero :)

  • Excellent script. Worked for me! Thanks!

  • Thanks, Kirk! Suspicioned for a long time that this would be possible, but had never ran into info that would lead me to the How. Have a need for this in an upgrade to SP2013 and am grateful for your post.

  • We have written SharePoint WSP Solutions Backup and Retention Powershell script based on above & have uploaded to Microsoft Gallery.

    msexchange.me/.../sharepoint-wsp-solutions-backup-and-retention

  • Just what I needed! Thanks!

Page 1 of 1 (9 items)
Leave a Comment
  • Please add 2 and 4 and type the answer here:
  • Post
Translate This Page
Search
Archive
Archives