SharePoint Pals
 | Sign In
How to Deploy a SharePoint 2013 Solution (WSP) in the Farm using PowerShell
by Sathish Nadarajan 28 Dec 2013
SharePoint MVP
Today  :   13     Total  :    26041

All of us will be using Visual Studio as our Development IDE for our development purpose. Once our development completes, Visual Studio itself prepares the WSP for us. We are delivering the WSP as a deliverable. Later on moving the WSP to a Staging, we require some sort of deployment procedure. For that, I would say PowerShell is the best Option. Let us, how to write a PowerShell Snippet to Deploy our WSP in Farm level as well as Web Application Level.

First we will see, how to deploy our WSP against a particular Web Application. The script is self-explanatory and commented with the steps.

Before, seeing the script, let us see the sequence of the script.

1. Get the Site, WebApplication URL, Solution Name, Solution Location.

2. Check whether the Solution is already installed.

3. If installed, then find, whether it is deployed in any of the WebApplication.

4. If deployed, then retract from all the web applications already deployed.

5. Then un-install the wsp.

6. Add the WSP.

7. Install the WSP against the WebApplication, which we are specifying.

This gives a proper validation for the deployment script. Now, let us see the script.

 Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
 function wait4timer($solutionName) 
     $solution = Get-SPSolution | where-object {$_.Name -eq $solutionName}    
     if ($solution -ne $null)     
         Write-Host "Waiting to finish soultion timer job" -ForegroundColor Green      
         while ($solution.JobExists -eq $true )          
             Write-Host "Please wait...Either a Retraction/Deployment is happening" -ForegroundColor DarkYellow           
             sleep 2            
         Write-Host "Finished the solution timer job" -ForegroundColor Green  
         # Get the WebApplicationURL
         $MyWebApplicationUrl = "http://WEBAPPLICATIONURL";
         # Get the Solution Name
         $MywspName = "MySolution.WSP"
         # Get the Path of the Solution
         $MywspFullPath = "D:\Test\MySolution.WSP"
         # Try to get the Installed Solutions on the Farm.
         $MyInstalledSolution = Get-SPSolution | Where-Object Name -eq $MywspName
         # Verify whether the Solution is installed on the Target Web Application
         if($MyInstalledSolution -ne $null)
             if($MyInstalledSolution.DeployedWebApplications.Count -gt 0)
                 # Solution is installed in atleast one WebApplication.  Hence, uninstall from all the web applications.
                 # We need to unInstall from all the WebApplicaiton.  If not, it will throw error while Removing the solution
                 Uninstall-SPSolution $MywspName  -AllWebApplications:$true -confirm:$false
                 # Wait till the Timer jobs to Complete
                 Write-Host "Remove the Solution from the Farm" -ForegroundColor Green 
                 # Remove the Solution from the Farm
                 Remove-SPSolution $MywspName -Confirm:$false 
                 sleep 3
                 # Solution not deployed on any of the Web Application.  Go ahead and Remove the Solution from the Farm
                 Remove-SPSolution $MywspName -Confirm:$false 
                 sleep 3
         # Add Solution to the Farm
         Add-SPSolution -LiteralPath "$MywspFullPath"
         # Install Solution to the WebApplication
         install-spsolution -Identity $MywspName -WebApplication $MyWebApplicationUrl -FullTrustBinDeployment:$true -GACDeployment:$false -Force:$true
         # Let the Timer Jobs get finishes       
         Write-Host "Successfully Deployed to the WebApplication" -ForegroundColor Green 
         Write-Host "Exception Occuerd on DeployWSP : " $Error[0].Exception.Message -ForegroundColor Red  

This will install against a particular WebApplication and the deployment is happening against the Bin Folder.

The Tags,

 -FullTrustBinDeployment:$true -GACDeployment:$false

Decides about the deployment type. If we want to do a GAC Deployment, then we need to give

 -FullTrustBinDeployment:$false -GACDeployment:$true

This will deploy against a particular Web Application. Some of the WSPs needs to be deployed globally. Let us see, how to do that and what are the tags required for them.

 install-spsolution -Identity $wsp –AllWebApplications:$true

This will deploy our WSP on all web applications.

Happy Coding.

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation