How to Deploy Multiple WSP Solutions using PowerShell in SharePoint

Requirement: Have a bunch of WSP solution packages and had to add and deploy all of them to a cloned SharePoint environment.

Solution: Lets bulk deploy all WSP solutions from a folder to SharePoint using PowerShell.

PowerShell script to bulk add Multiple solutions:
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

Function WaitForInsallation([string] $SolutionName)
{
        Write-Host -NoNewline "Waiting for deployment job to complete" $SolutionName "."
        $WSPSol = Get-SPSolution $SolutionName
        while($wspSol.JobExists)
        {
            sleep 2
            Write-Host -NoNewline "."
            $wspSol = Get-SPSolution $SolutionName
        }
        Write-Host "job Completed" -ForegroundColor green
}

Function Deploy-SPSolution ($WSPFolderPath)
{
    #Get all wsp files from the given folder
    $WSPFiles = Get-childitem $WspFolderPath | where {$_.Name -like "*.wsp"}

    #Iterate through each wsp and Add in to the solution store
    ForEach($File in $wspFiles)
    {
        $wsp = Get-SPSolution | Where {$_.Name -eq $File.Name}

        if($wsp -eq $null)
        {
            write-host "Adding WSP solution:"$File.Name
            Add-SPSolution -LiteralPath ($WspFolderPath + "\" + $file.Name)
        }
        else
        {
            write-host "solution already exists!"

        }
    }
}

try
{
        Deploy-SPSolution "C:\WSPFiles"
}
catch
{
    write-host $_.exception
} 
Once added to the SharePoint solution store, You can either deploy them to the targeted web applications/globally using PowerShell,
Install-SPSolution -Identity "Solution-Name" -Webapplication "Web-App-URL" -GacDeployment -Force
or use the below code to deploy all solutions in one go:
#Deploy all installed solutions in the farm
Get-SPSolution | ForEach-Object { if (!$_.Deployed) {
 If ($_.ContainsWebApplicationResource -eq $False) {
    Install-SPSolution -Identity $_ -GACDeployment 
 }
else {
    Install-SPSolution -Identity $_ -AllWebApplications -GACDeployment 
  }
 }
}

Deploy SharePoint Solution Manually:
or You can deploy from SharePoint Central Administration site manually.
  • Navigate to SharePoint 2013/2016 Central Administration site.
  • Click on System Settings >> Manage Farm Solutions under Farm Management
  • Pick the relevant solution from the solution store
  • Click on "Deploy Solution" to start deploying the solution.
    sharepoint powershell deploy multiple solutions
You may also have to activate necessary features that came through deployed solutions!

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.