Install wsp files placed in the same directory with PowerShell script

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 = $;

   # 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";     

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s