Question

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

Was it helpful?

Solution

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

}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top