Tags

,

If you are required to deploy a big number of wsp files, the best way is to put them in the same folder with PowerShell script and make the script install them one by one. This way you won’t need to spend time to execute Add-SPSolution and Install-SPSolution for each one.

Add-PSSnapin Microsoft.SharePoint.Powershell;

# Input the web application name
$webApplication = Read-Host "Please enter the web application name";
# Calculate the script directory
$scriptDirectory = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition;
# Get the wsp files placed in script directory
Write-Host "Retreiving *.wsp files";
$wspFiles= Get-ChildItem $scriptDirectory *.wsp|where-object {!($_.psiscontainer)};

# Iterate through all wsp files and add and install them
foreach($wspFile in $wspFiles) {
   
   $solutionPath = $wspFile.FullName;
   $solutionName = $wspFile.name;

   # Add solution
   Write-Host "Adding solution " + $solutionName;
   Add-SPSolution $solutionPath;
   Write-Host  $solutionName + " was added to succesfully"; 
   
   # Install solution
   Write-Host "Installing solution " + $solutionName;
   Install-SPSolution -Identity $solutionName -WebApplication $webApplication -GacDeployment;
   Write-Host $solutionName + " was installed succesfully";     
    
}
Advertisements