Share via


How to Deploy a SharePoint 2010 Solution Package Using Windows PowerShell

This topic provides guidance on how to use Microsoft Windows PowerShell to deploy a Microsoft SharePoint 2010 Web Solution Packages (WSP).

Prerequisites

To deploy a SharePoint Solution Packages (WSP) using Windows PowerShell

The following example uses the sample Windows PowerShell script (available in SharePointScripts.zip) to deploy the SharePoint Solution packages (WSP) used for the Solution Storefront. The process involves two distinct actions; adding the WSP files to the Microsoft SharePoint 2010 environment, and then installing them.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

.\"1-env.ps1"

$farm = get-spfarm

Write-Host "Adding the Solutions"

if($farm.Servers.Count -gt 1)
{
    $FarmProvisioningSolutionPath = $PathToSolutionFiles + $SolutionNameFarmProvisioningLib
    Add-SPSolution -LiteralPath $FarmProvisioningSolutionPath
}

$WebPartSolutionPath = $PathToSolutionFiles + $SolutionNameWebPart
Add-SPSolution -LiteralPath $WebPartSolutionPath
$SiteTemplateSolutionPath = $PathToSolutionFiles + $SolutionNameSiteTemplate
Add-SPSolution -LiteralPath $SiteTemplateSolutionPath
$BusinessMgtSolutionPath = $PathToSolutionFiles + $SolutionNameBusinessMgt
Add-SPSolution -LiteralPath $BusinessMgtSolutionPath

Write-Host "Deploying the solutions"

if($farm.Servers.Count -gt 1)
{
    Install-SPSolution -Identity $SolutionNameFarmProvisioningLib -GACDeployment -Force
}

Install-SPSolution -Identity $SolutionNameWebPart -GACDeployment -WebApplication $WebAppName -Force
Install-SPSolution -Identity $SolutionNameSiteTemplate -GACDeployment -WebApplication $WebAppName -Force
Install-SPSolution -Identity $SolutionNameBusinessMgt -GACDeployment -WebApplication $WebAppName -Force


Write-Host "Solutions deploying... this may take a few minutes to complete."

$WebPartDeployed = 0;
$SiteTemplateDeployed = 0;
$BusinessMgtDeployed = 0;
$totalDeployed = 0;
do {
  
  if($WebPartDeployed -eq 0){
      $webSol = Get-SPSolution -Identity $SolutionNameWebPart
      if($webSol.Deployed)
      {
          foreach($item in $webSol.DeployedWebApplications) 
          { 
            if ($item.DisplayName -eq $WebAppName) 
            { 
                $WebPartDeployed = 1; 
                break;
            }
          }        
      }
  }
  
  if($SiteTemplateDeployed -eq 0){
      $templateSol = Get-SPSolution -Identity $SolutionNameSiteTemplate
      if($templateSol.Deployed)
      {
          foreach($item in $templateSol.DeployedWebApplications) 
          { 
            if ($item.DisplayName -eq $WebAppName) 
            { 
                $SiteTemplateDeployed = 1; 
                break;
            }
          }  
      }
  }
  
  if($BusinessMgtDeployed -eq 0){
      $businessSol = Get-SPSolution -Identity $SolutionNameBusinessMgt
      if($businessSol.Deployed)
      {       
          foreach($item in $templateSol.DeployedWebApplications) 
          { 
            if ($item.DisplayName -eq $WebAppName) 
            { 
                $BusinessMgtDeployed = 1; 
                break;
            }
          } 
      }
  }
  
  $totalDeployed = $WebPartDeployed + $SiteTemplateDeployed + $BusinessMgtDeployed;
  
  if($totalDeployed -lt 3)
  {
    Write-Host ".";
    sleep 3;
  }
}
while ( $totalDeployed -lt 3)

Write-Host "."
Write-Host "All applications are now deployed"

Note

Make sure to allow some time for WSPs to deploy completely. Use SharePoint 2010 Central Admin to verify the deployment status.

See Also

Other Resources

Using Windows PowerShell for SharePoint 2010 Commerce Deployment

Walkthrough: Deploying SharePoint 2010 Commerce Solution in a Two-Tier Topology

Walkthrough: Deploying a SharePoint 2010 Commerce Solution in a Three-Tier Topology