Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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

}
share|improve this answer
    
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. –  Arko D Jun 11 '12 at 9:52
    
Here is a really good start to get hands-on PowerShell amazon.com/Automating-SharePoint-2010-Windows-PowerShell/dp/… –  Falak Mahmood Jun 11 '12 at 14:44

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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