Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog



Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

Adding and Deploying Solutions with PowerShell in SharePoint 2010

Visual Studio 2010 makes it really easy to add and deploy solutions when you are developing, but you may eventually want to deploy those solution packages elsewhere right?  We can still use stsadm, but that is effectively considered deprecated now in favor of PowerShell.  In the past to add a solution, we used an stsadm command like the one below.  In today’s example, we’ll be working with a package called SharePointProject2.wsp on my server named sp2010.

stsadm –o addsolution –name SharePointProject2.wsp

To get started with PowerShell, run the SharePoint 2010 Management Console located in your Microsoft SharePoint 2010 Products folder on your start menu.  This automatically loads the Microsoft.SharePoint.PowerShell snappin so that we can execute SharePoint commands.  To install a solution we use the Add-SPSolution command.  If you are using a Sandboxed solution you would use Add-SPUserSolution instead.  It takes just one parameter, –literalpath, which is the path to the solution file.  One thing that is different is that you must specify the full path to the file for some reason.  I haven’t been able to get it to take a path to the solution in the current folder even if I make use of .\ before the filename.  Here is an example.

Add-SPSolution c:\code\SharePointProject2\bin\debug\SharePointProject2.wsp

In this case you don’t actually have to type –literalpath before the parameter.  This is what it looks like when executed.  You can see that it displays the id of the solution along with its deployment status.


Now we need to deploy the solution.  In the past, we used an stsadm command like the following.

stsadm –o deploysolution –name SharePointProject2.wsp –url http://moss-server –allowCasPolicies –immediate

We would also follow this up with a call to stsadm with the execadmsvcjobs operation.  To do the same operation in PowerShell, we use the Install-SPSolution command (again use Install-SPUserSolution for Sandboxed solutions).  You can use the Get-Help command (i.e.: Get-Help Install-SPSolution) to get more information on a command but it’s not always obvious what it is expecting as you can see below.  That is why I am writing the post today.


The first parameter you need is the –Identity parameter.  This is the name of the solution package (i.e.: MySolution.wsp).  Depending on if you are using the GAC or Code Access Security, you will specify either –GACDeployment or –CASPolicies.  You then need to specify a specific web application using the –WebApplication parameter or –AllWebApplications to deploy it to all web applications (assuming the manifest allows it).  If you need to force the deployment, you can still use the –Force command.  Here is what an install command might look like.

Install-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010 -GACDeployment

I’ll point out that executing this command actually does do the deployment operation.  You don’t have to fire off something to execute a job later like you did with stsadm.

You might want to update your solution, so we’ll talk about how to do that as well.  Here is what your stsadm command might have looked like in WSS3.  Which would also be followed up with an execadmsvcjobs operation.

stsadm –o upgradesolution –name SharePointProject2.wsp –filename SharePointProject2.wsp –immediate –allowCasPolicies

The upgrade solution syntax is similar to the others.  We just have to specify an identity and a literalpath with the Update-SPSolution command.  The identity is the name of the package on the server to upgrade and the literalpath is the full path to the new solution package on the file system.  Here is what that might look like.

Update-SPSolution –Identity SharePointProject2.wsp –LiteralPath c:\code\SharePointProject2\bin\debug\SharePointProject2.wspGACDeployment

We’ve talked about everything else, so we’ll finish it up by talking about retraction and removal.  To retract a solution we use the Uninstall-SPSolution command.  By now you are probably noticing a pattern in the way things are named.  Install –> Deploys, Uninstall –> Retracts.  It also just uses the -Identity parameter and the –WebApplication parameter.  You can also use the –AllWebApplications parameter to retract it from all web applications. Many of these commands may prompt you with an “Are you sure?” type prompt.  You can skip this prompt by adding a –confirm parameter.  Here is what it looks like.

Uninstall-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010

Lastly, to remove the package from the solution store, we use the Remove-SPSolution command.  It just takes the name of the package.

Remove-SPSolution –Identity SharePointProject2.wsp

I hope this helps.  If you’re like me, it’s one thing to see the docs on something, but I like to see real examples.  There aren’t any examples in the Get-Help command yet.  This should cover all of the common commands that you probably used to used with stsadm in regards to solution deployment.  The nice thing is that you can script these things together very easily and create highly flexible PowerShell scripts.  Expect a few more posts soon on the basics of working with PowerShell and SharePoint 2010.

To learn more about using PowerShell with features, see Activating and Deactivating Features with PowerShell



Twitter Trackbacks for Adding and Deploying Solutions with PowerShell in SharePoint 2010 - Corey Roth - - Tip of the [] on said:

Pingback from  Twitter Trackbacks for                 Adding and Deploying Solutions with PowerShell in SharePoint 2010 - Corey Roth - - Tip of the         []        on

December 2, 2009 3:17 PM

uberVU - social comments said:

This post was mentioned on Twitter by sharepointbuzz: #SharePoint Adding and Deploying Solutions with PowerShell in SharePoint 2010: Visual Studio 2010 makes it really e...

December 2, 2009 3:56 PM

Steps To Install WSP file in STSADM « Dot Net Solutions said:

Pingback from  Steps To Install WSP file in STSADM « Dot Net Solutions

March 10, 2010 7:01 AM

ynuska said:


I tried this command to install a BCS solution

Install-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010 -GACDeployment

but I gives me the next error "

This solution contains no resources scoped for a Web appli

cation and cannot be deployed to a particular Web application."

I tried with

Install-SPSolution –Identity SharePointProject2.wsp

–GACDeployment and I doesn't do anything. I checked and the solution it's not installed :(,

Can you help me pls with this ?


May 12, 2010 7:03 AM

Chris said:

I have the same issue as above

This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.

June 4, 2010 3:11 AM

Martin said:

Add-SPSolution can take the solution in the current folder if you specify the $(Get-ChildItem <path>) as the LiteralPath. For example:

Add-SPSolution -LiteralPath $(Get-Childitem mysolution.wsp)

July 26, 2010 2:50 PM

CoreyRoth said:

@Martin Good to know.  Thanks for the tip.

@Chris @ynuska If your project doesn't have any features scoped for a specific web application, use the -AllWebApplications parameter instead of the -Url parameter.

July 26, 2010 3:11 PM

AidanQ said:

If the solution has no web application resources it is considered a global solution and does not actually need to target an web applications. Remove the -AllWebApplicaitons and this global solution will be deployed globally to the farm and will be available to all web applications

August 23, 2010 9:51 AM

Zootius said:

This is an excellent post, really helpful. Cheers!

September 30, 2010 4:03 AM

Sharepoint 2010 Subsites webpart | said:

Pingback from  Sharepoint 2010 Subsites webpart |

October 7, 2010 5:12 AM

Deploying WSP solution files in Sharepoint 2010 « Alen Ziver Malhasoglu's Microsoft Commerce Server Blog said:

Pingback from  Deploying WSP solution files in Sharepoint 2010 &laquo; Alen Ziver Malhasoglu&#039;s Microsoft Commerce Server Blog

October 12, 2010 3:55 PM

Brad said:

Very helpful.  Thanks!

November 11, 2010 3:27 PM

Tania said:

This PowerShell concept is really different and very interesting to read. The tips gave me many useful things. But i have one doubt that is this resource has no web application can you explain about it? Thanks...

December 14, 2010 3:26 AM

Adding deploying solutions using powershell + sharepoint 2010 « Nathasha88's Blog said:

Pingback from  Adding deploying solutions using powershell + sharepoint 2010 &laquo; Nathasha88&#039;s Blog

December 14, 2010 4:39 AM

Rahul Vartak said:

Nice Article Corey.. !! Liked the one to one comparison of PowerShell with STSADM commands..

Here's a blog I wrote noting steps for other deployment approaches with snapshots..

December 15, 2010 3:40 AM

Alex Angas said:

Hi Corey,

This is the shortest syntax I've found to add a solution from the current folder:

add-spsolution "$(gl)\SharePointProject2.wsp"


HTH, Alex.

January 17, 2011 8:09 PM

Jay said:

Great article.  Just an FYI the -name should be -filename when adding a solution.

stsadm –o addsolution –filename sharePointProject2.wsp

February 17, 2011 3:17 PM

Leonardo said:

I ran the command to install the wsp but it gives me no output, so i don't know if the command had any effect or not. I browse the site and i can't find my webpart anywhere. Am i missing something?

March 11, 2011 5:15 PM

CoreyRoth said:

@Leo Check your solution gallery in Central Administration to verify that the solution was installed.  You won't see your web part anywhere until you activate the site collection feature associated with it.  You can use a separate PowerShell command to activate features (more info can be found on this site).

March 22, 2011 11:36 PM

SharePoint 2010: Pasos para instalar una solución! « Pasi??n por la tecnolog??a… said:

Pingback from  SharePoint 2010: Pasos para instalar una soluci&oacute;n! &laquo; Pasi??n por la tecnolog??a&#8230;

March 25, 2011 4:18 AM

Blog del CIIN said:

A la hora de instalar soluciones de SharePoint (m&aacute;s conocidas como WSPs), tenemos tres o cuatro

March 25, 2011 4:22 AM

djeeg said:

I built an app to help remember powershell commands

March 29, 2011 10:15 PM

My resource to learn on 70-573 « martinbodocky said:

Pingback from  My resource to learn on 70-573   &laquo; martinbodocky

May 11, 2011 5:23 AM

Bijay said:

Here in the below site I have tried to explain the deployment process

May 17, 2011 5:50 AM

Anupam Kaul said:

This assumes that the script is executed on the same same server which has a Sharepoint installation. However how do you tackle this  when you want to deploy to a SP Server remotely e.g. from a CI Server?

Assume that I auto-build my solution on Server 1 and would like to deploy this solution to multiple environments (test, pre-prod, prod). Is it possible to give the URL parameter to the AddSPSolution cmdlet (and other subsequent cmdlets) so that I can deploy this to multiple environments without necessarily copying all the WSP's and the script to deploy to each individual environment?

Many thanks for any help here.

May 27, 2011 4:09 AM

CoreyRoth said:

@Anumpam That is correct.  To my knowledge, the solution packages always need to be on the target machine.  It is possible to execute these commands using PowerShell remoting though, but I haven't looked into the details.

May 30, 2011 9:22 PM

ThinLizzy7 said:

Tried to use but keep getting error, any ideas?  

Add-SPSolution : This solution contains one or more assemblies targeted for the

global assembly cache. You should use a strong name for any assembly that will

be in the global assembly cache.

At line:1 char:15

+ Add-SPSolution <<<<  -LiteralPath "C:\Projects\Deployment\file.wsp"

   + CategoryInfo          : InvalidData: (

July 26, 2011 2:31 PM

CoreyRoth said:

@ThinLizzy7 This means that the assembly you built is not strongly named.  You can specify a strong name key in the properties of your project in Visual Studio.  Rebuild the package and then you should be able to deploy it.

July 27, 2011 9:40 PM

CoreyRoth said:

One thing I have left out is that you have to force the admin services jobs to run still just like in 2007.  To do so, use the following after any install / uninstall command.

Stop-Service SPAdminV4


Start-Service SPAdminV4

August 31, 2011 3:47 PM

Dave Stuart said:

Corey, I want to deploy a new version of a Web Part that is already deployed as version So I want version to still exist and I want the new version to also be in the GAC. If I do an Update-SPSolution it overwrites the version that is on the application and breaks it. How can I do deploy a new revision and not break what I have already deployed?



August 31, 2011 11:51 PM

CoreyRoth said:

@Dave If you are going to keep the original version, you will have to build a new solution package that has a different name and guid.  Since you are using Update, it's going to replace whatever is out there.  Now you could also possibly get around this by just creating a new .webpart file with a different name.

September 1, 2011 11:06 AM

Led to Slaughter» Blog Archive » Debugging SharePoint said:

Pingback from  Led to Slaughter&raquo; Blog Archive &raquo; Debugging SharePoint

September 7, 2011 11:35 PM

How to develop custom workflow actions in SharePoint 2010 | eabsoft said:

Pingback from  How to develop custom workflow actions in SharePoint 2010 | eabsoft

September 10, 2011 3:44 PM

Curia Damiano blog said:

SharePoint 2010 and PowerShell guide for wsp deployment

October 14, 2011 11:49 AM

smw said:

How about retracting two solutions back to back?  If I issue a batch command to remove all my solutions how can I accomplish it without getting the 'A deployment or retraction is already under way for the solution' error?


October 19, 2011 9:59 AM

CoreyRoth said:

@smw Try issuing both commands and then running the admin services job.

November 7, 2011 8:27 PM

Putz! Vou ter que fazer outro Deploy! =S « sharepointgirl said:

Pingback from  Putz! Vou ter que fazer outro Deploy!  =S &laquo; sharepointgirl

December 8, 2011 12:30 PM

Problem with HTTP Handler deployed on Sharepoint 2010 | Q&A System said:

Pingback from  Problem with HTTP Handler deployed on Sharepoint 2010 | Q&amp;A System

December 13, 2011 8:36 AM

SharePoint 2010 – How to activated and deactivated Features with PowerShell | SharePoint - How To said:

Pingback from  SharePoint 2010 &#8211; How to activated and deactivated Features with PowerShell | SharePoint - How To

December 29, 2011 4:25 AM

Rajan said:

I have a different issue. I uninstalled a webparts solution. But not able to retarct it. In Manage farm solutions, I can see the status as "retracting" always. Not sure why this is happening. I want to remove the solution completely from sharepoint.

While clicking that particular webpart, I got the error message as the web.config doest not have the <trust> node.

January 12, 2012 10:29 PM

SharePoint 2007 Solution in SharePoint 2010 deployen - SharePointBlog said:

Pingback from  SharePoint 2007 Solution in SharePoint 2010 deployen - SharePointBlog

January 20, 2012 3:32 PM

nholling said:

smw: You need to wait for the job to finish. You can poll something like "stsadm -o enumdeployments" to wait for the job to finish. Once the job is finish, run the second deploy.

February 27, 2012 1:31 PM

T???o và deploy Silverlight Webpart v???i Visual Studio 11 beta (SharePoint 2010) « Huy's space – That's the way it is said:

Pingback from  T???o v&agrave; deploy Silverlight Webpart v???i Visual Studio 11 beta (SharePoint 2010) &laquo;  Huy&#039;s space &#8211; That&#039;s the way it is

March 6, 2012 3:31 AM

New version of the SubSites webpart available as a free download | said:

Pingback from  New version of the SubSites webpart available as a free download |

April 2, 2012 4:28 AM

Andy Maggs said:

You may use Resolve-Path to work with .\ paths e.g.

Add-SPSolution -LiteralPath (Resolve-Path .\$solutionname)

May 8, 2012 5:52 AM

Bijay said:

Very well explained but You can check the below link too

May 10, 2012 2:39 AM

WaveRipper said:

The gold is in deploying GAC solutions without downtime. you can use the -local parameter to add to each server in an enterprise and it will not lock the database. Give it a shot ;)

December 4, 2012 5:25 PM

SAM said:


April 30, 2013 10:58 AM

Chris Barba said:

How to deploy a feature through PowerShell

July 16, 2013 3:23 PM

How to deploy a feature through PowerShell | Random Technical Thoughts said:

Pingback from  How to deploy a feature through PowerShell | Random Technical Thoughts

July 16, 2013 3:50 PM

Leave a Comment


About CoreyRoth

Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems