Using Powershell to export all solutions from current 2010 farm and programatically import and deploy them
Sitting on client site with Shane Young and Jeff Jacobs today we came across a challenging scenario. While trying to migrate their current production to another farm, as well as stand up a new Integration farm, we came to the realization they may not have the binaries for all their custom designed solutions. What we needed was a way to ensure the same solutions were deployed to each farm. Well we found a neat little way to do this using Powershell.
Extract all solutions from your farm
(Get-SPFarm).Solutions | ForEach-Object{$var = (Get-Location).Path + "\" + $_.Name; $_.SolutionFile.SaveAs($var)}
** I must note here that utilizing the (Get-Location).Path will drop all the solutions where you currently located in the file system, so ensure to navigate to the appropriate folder before running this command, or modify the command to hard code in the path you need. We do not like hard coded path's therefore we just call our current location.
Import all solutions to another farm
Get-ChildItem | ForEach-Object{Add-SPSolution -LiteralPath $_.Fullname}
** Once again this calls your current location in the filesystem so ensure you navigate to the folder containing your newly exported solutions prior to executing this script.
Deploy all solutions on the new farm
Get-SPSolution | ForEach-Object {If ($_.ContainsWebApplicationResource -eq $False) {Install-SPSolution -Identity $_ -GACDeployment} else {Install-SPSolution -Identity $_ -AllWebApplications -GACDeployment}}
Once this is executed it will take 10 minutes or more for the solutions to deploy, depending on the number of solutions of course. So now you have a programmatic/repeatable method to ensure your farms have identical solutions.
Shane Young also wrote up a blog on this located here. For sake of saving myself some typing, I am just putting the bare bones code here. If you need a detailed explanation of what each command does please visit Shane's blog as he does a great job explaining in detail.
Comments
Anonymous
May 14, 2013
The above link to Shane's blog doesn't work. This should be the correct one: msmvps.com/.../using-powershell-to-export-all-solutions-from-your-sharepoint-2010-farm-and-other-fun.aspxAnonymous
October 06, 2014
Sven, that link no longer works as wellAnonymous
November 18, 2014
Latest version of the famous link, blogs.msmvps.com/.../using-powershell-to-export-all-solutions-from-your-sharepoint-2010-farm-and-other-fun.