Export/Import SharePoint 2010 solutions using PowerShell (Part 1/3)


When working with solutions in SharePoint 2010, it can be hard to track the location of your latest WSP’s. To resolve this, I created a script that will export all currently deployed solutions to your local hard drive.

Part 1 – Export all deployed solutions from the SharePoint 2010 environment

The following script can be copied into notepad and saved as a .ps1 file. Just execute the script to export the solutions. When you run the script, it will ask for an export location. This folder does not have to exist on your harddrive.

#Export all SharePoint 2010 solutions
Add-PSSnapin Microsoft.SharePoint.PowerShell</span>

#This is the path that will be used to import/export the solutions.
$ExportPath = Read-Host "Enter the export location (eg. C:\Solutions). This directory will be created if it doesn't exist"

function checkCreatePath($checkPath)
#Check if the path already exists
if((Test-Path $checkPath) -eq $False)
#if the path does not exist, it will be created
New-Item $checkPath -type Directory | out-null
Write-Host "Directory created" -fore green
#if the path does not exist, you will be notified
Write-Host "Directory already exists" -fore green
#Run the exportAllSolutions</span>

function exportAllSolutions($path)
#The following line will export all solutions that are deployed in your current farm
(Get-SPFarm).Solutions | where{$_.Deployed -ne $null} | ForEach-Object{$solution = $path + "" + $_.Name; $_.SolutionFile.SaveAs($solution); Write-Host "Exporting $solution"}
Write-Host "All solutions are exported to $exportPath, press any key to exit" -fore green
#The following line will wait for user input to exit the script
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")


Running this script on a test environment, resulted in the following:
Export solutions using PowerShell

The directory C:MySolutions now contains 11 solutions. In a live environment, you would now copy the folder with all the solutions to another SharePoint environment.

In part 2 I will share a script that will import these solutions into another SharePoint 2010 farm.

Leave a Reply

Your email address will not be published. Required fields are marked *