Adding and Deploying Solutions with PowerShell in SharePoint 2010

Posted Wednesday, December 2, 2009 1:25 PM by CoreyRoth

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.

PowerShellAddSolution

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.

PowerShellGetHelpInstallSolution

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

Comments

# Twitter Trackbacks for Adding and Deploying Solutions with PowerShell in SharePoint 2010 - Corey Roth - DotNetMafia.com - Tip of the [dotnetmafia.com] on Topsy.com

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

# Social comments and analytics for this post

Wednesday, December 2, 2009 3:56 PM by uberVU - social comments

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... http://bit.ly/8i2lc1

# Steps To Install WSP file in STSADM « Dot Net Solutions

Wednesday, March 10, 2010 7:01 AM by Steps To Install WSP file in STSADM « Dot Net Solutions

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Wednesday, May 12, 2010 7:03 AM by ynuska

Hello,

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 ?

Thx,

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Friday, June 4, 2010 3:11 AM by Chris

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.

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, July 26, 2010 2:50 PM by Martin

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)

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, July 26, 2010 3:11 PM by CoreyRoth

@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.

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, August 23, 2010 9:51 AM by AidanQ

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Thursday, September 30, 2010 4:03 AM by Zootius

This is an excellent post, really helpful. Cheers!

# Sharepoint 2010 Subsites webpart | www.SharePoint247.com

Thursday, October 7, 2010 5:12 AM by Sharepoint 2010 Subsites webpart | www.SharePoint247.com

Pingback from  Sharepoint 2010 Subsites webpart | www.SharePoint247.com

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

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Thursday, November 11, 2010 3:27 PM by Brad

Very helpful.  Thanks!

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, December 14, 2010 3:26 AM by Tania

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...

godwinsblog.cdtech.in/.../sharepoint-2010-root-of-certificate.html

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

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Wednesday, December 15, 2010 3:40 AM by Rahul Vartak

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..

rahul-vartak.blogspot.com/.../deploying-sharepoint-2010-sites-using.html

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, January 17, 2011 8:09 PM by Alex Angas

Hi Corey,

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

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

Reference: blog.mastykarz.nl/easy-installing-sharepoint-2010-solutions-powershell

HTH, Alex.

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Thursday, February 17, 2011 3:17 PM by Jay

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

stsadm –o addsolution –filename sharePointProject2.wsp

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Friday, March 11, 2011 5:15 PM by Leonardo

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?

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, March 22, 2011 11:36 PM by CoreyRoth

@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).

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

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

# SharePoint 2010: Pasos para instalar una solución!

Friday, March 25, 2011 4:22 AM by Blog del CIIN

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, March 29, 2011 10:15 PM by djeeg

I built an app to help remember powershell commands http://sppower.codeplex.com/

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

Wednesday, May 11, 2011 5:23 AM by My resource to learn on 70-573 « martinbodocky

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, May 17, 2011 5:50 AM by Bijay

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

www.fewlines4biju.com/.../deploy-wsp-file-in-sharepoint-2010.html

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Friday, May 27, 2011 4:09 AM by Anupam Kaul

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.

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, May 30, 2011 9:22 PM by CoreyRoth

@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.

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, July 26, 2011 2:31 PM by ThinLizzy7

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: (

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Wednesday, July 27, 2011 9:40 PM by CoreyRoth

@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.

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Wednesday, August 31, 2011 3:47 PM by CoreyRoth

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-SPAdminJob

Start-Service SPAdminV4

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Wednesday, August 31, 2011 11:51 PM by Dave Stuart

Corey, I want to deploy a new version of a Web Part that is already deployed as version 1.1.0.0. So I want version 1.0.0.0 to still exist and I want the new version 1.1.0.0 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?

Thanks

Dave

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Thursday, September 1, 2011 11:06 AM by CoreyRoth

@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.

# Led to Slaughter&raquo; Blog Archive &raquo; Debugging SharePoint

Wednesday, September 7, 2011 11:35 PM by Led to Slaughter» Blog Archive » Debugging SharePoint

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

# How to develop custom workflow actions in SharePoint 2010 | eabsoft

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

# SharePoint 2010 and PowerShell guide for wsp deployment

Friday, October 14, 2011 11:49 AM by Curia Damiano blog

SharePoint 2010 and PowerShell guide for wsp deployment

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Wednesday, October 19, 2011 9:59 AM by smw

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?

smw

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, November 7, 2011 8:27 PM by CoreyRoth

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

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

Thursday, December 8, 2011 12:30 PM by Putz! Vou ter que fazer outro Deploy! =S « sharepointgirl

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

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

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

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

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Thursday, January 12, 2012 10:29 PM by Rajan

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.

# SharePoint 2007 Solution in SharePoint 2010 deployen - SharePointBlog

Pingback from  SharePoint 2007 Solution in SharePoint 2010 deployen - SharePointBlog

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Monday, February 27, 2012 1:31 PM by nholling

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.

# 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

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

# New version of the SubSites webpart available as a free download | www.SharePoint247.com

Pingback from  New version of the SubSites webpart available as a free download | www.SharePoint247.com

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, May 8, 2012 5:52 AM by Andy Maggs

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

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

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Thursday, May 10, 2012 2:39 AM by Bijay

Very well explained but You can check the below link too

www.fewlines4biju.com/.../this-solution-contains-no-resources.html

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, December 4, 2012 5:25 PM by WaveRipper

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 ;)

# re: Adding and Deploying Solutions with PowerShell in SharePoint 2010

Tuesday, April 30, 2013 10:58 AM by SAM

Thanks

# How to deploy a feature through PowerShell

Tuesday, July 16, 2013 3:23 PM by Chris Barba

How to deploy a feature through PowerShell

# How to deploy a feature through PowerShell | Random Technical Thoughts

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

# SharePoint 2010 and PowerShell guide for wsp deployment

Wednesday, October 15, 2014 9:03 AM by Curia Damiano blog

SharePoint 2010 and PowerShell guide for wsp deployment

# Installation und Konfiguration | wiki.smarterbusiness.eu

Pingback from  Installation und Konfiguration | wiki.smarterbusiness.eu

# Installation und Konfiguration | wiki.smarterbusiness.eu

Pingback from  Installation und Konfiguration | wiki.smarterbusiness.eu

# Moving the blog to Azure and the origin of DotNetMafia.com

Tuesday, August 4, 2015 1:08 PM by Corey Roth [MVP]

When we built dotnetmafia.com, we used one of the most common blog engines around Community Server by

# Example | wiki.smarterbusiness.eu

Thursday, August 13, 2015 2:42 AM by Example | wiki.smarterbusiness.eu

Pingback from  Example | wiki.smarterbusiness.eu

# Sharxx Icons f??r F??lligkeiten | wiki.smarterbusiness.eu

Wednesday, September 2, 2015 5:14 AM by Sharxx Icons f??r F??lligkeiten | wiki.smarterbusiness.eu

Pingback from  Sharxx Icons f??r F??lligkeiten | wiki.smarterbusiness.eu

# Sharxx Icons f??r F??lligkeiten | wiki.smarterbusiness.eu

Wednesday, September 2, 2015 5:14 AM by Sharxx Icons f??r F??lligkeiten | wiki.smarterbusiness.eu

Pingback from  Sharxx Icons f??r F??lligkeiten | wiki.smarterbusiness.eu

# Sharepoint Backup Solutions |

Wednesday, March 2, 2016 11:30 AM by Sharepoint Backup Solutions |

Pingback from  Sharepoint Backup Solutions |

# Sharepoint Solutions |

Friday, March 25, 2016 10:41 PM by Sharepoint Solutions |

Pingback from  Sharepoint Solutions |

Leave a Comment

(required) 
(required) 
(optional)
(required)