2

I am trying to migrate around 200 wsps from one SharePoint 2010 farm to another. I have already copied the wsp files to a folder in the new farm.

I need a powershell script that can take the path of the folder as input and add all the wsps located in the folder to the farm. I do not wish to deploy rather just add them to the farm.

Example Input:-

C:\EXPORTEDWSP

2 Answers 2

4

Just provide the path of the folder where WSP is located and the function will add all the WSPs in Solution store.

Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
function WaitForInsallation([string] $Name)
{
        Write-Host -NoNewline "Waiting for deployment job to complete" $Name "."
        $wspSol = get-SpSolution $Name
        while($wspSol.JobExists)
        {
            sleep 2
            Write-Host -NoNewline "."
            $wspSol = get-SpSolution $Name
        }
        Write-Host "job ended" -ForegroundColor green
}
Function Deploy-SPSolution ($WspFolderPath)
{
    $wspFiles = get-childitem $WspFolderPath | where {$_.Name -like "*.wsp"}

    ForEach($file in $wspFiles)
    {
        $wsp = Get-SPSolution | Where{$_.Name -eq $file.Name}
        if($wsp -eq $null)
        {
            write-host "Adding solution"
            Add-SPSolution -LiteralPath ($WspFolderPath + "\" + $file.Name)
        }
        else
        {
            write-host "solution already exists"

        }

    }
}
try
{
        Deploy-SPSolution "C:\EXPORTEDWSP"
}
catch
{
    write-host $_.exception

}
2
  • Thanks a lot Falak, It works perfect !! Although its a bit out of the context of this question but I was wondering if you can point me to some good books or videos for working on Powershell with SharePoint 2010.
    – ArkoD
    Jun 11, 2012 at 9:52
  • Here is a really good start to get hands-on PowerShell amazon.com/Automating-SharePoint-2010-Windows-PowerShell/dp/… Jun 11, 2012 at 14:44
0

If you have a folder of WSPs only on a clean farm, script can be shortened to:

$names = get-childitem F:\SPProdSolutionsExtract
foreach ($solution in $names) {Add-SPSolution -LiteralPath ("F:\SPProdSolutionsExtract\" + $solution.Name) }

I use SharePoint Farm Solution Extractor to get the WSPs from one server and the above script to add them to the farm. The install-solution script is more work, since there are so many types of WSPs and parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.