Adding and Deploying Sandboxed Solutions Using PowerShell
Posted
Monday, May 21, 2012 9:09 PM
by
CoreyRoth
One of my most popular posts on DotNetMafia.com is my post on using PowerShell to add and deploy SharePoint solution packages (.wsp files). However, in that post, I never went in detail in deploying sandboxed solutions. Today, I want to talk about that and show you what you need to know. I started by using Visual Studio 11 to build a sandboxed solution using the new Visual Web Part.
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 will use the Add-SPUserSolution command. It takes two parameters. Specify –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. You then need to specify the URL to the site collection with the –site parameter. Here is an example.
Add-SPUserSolution –LiteralPath c:\code\SandboxedSolutionProject.wsp –Site http://sp2010/sites/sandbox
It looks like this in PowerShell. If it executes successfully, you’ll just be returned to the command prompt.
We can now see our .wsp file in the solution gallery.
We can see the solution package but note that it is not activated. For that, we need Install-SPUserSolution. It’s parameters are similar. We use –Identity with the name of the solution package (minus the path) and the –Site parameter with the URL of the site collection again.
Install-SPUserSolution –Identity SandboxedSolutionProject.wsp –Site http://sp2010/sites/sandbox
Once activated you can confirm it in the solutions gallery. You can now activate features as desired (using PowerShell if you want).
At some point, you might want to remove your solution. We can do that with PowerShell as well. First, we need to deactivate the solution using Uninstall-SPUserSolution. It takes the exact same parameter as Install-SPUserSolution.
Uninstall-SPUserSolution –Identity SandboxedSolutionProject.wsp –Site http://sp2010/sites/sandbox
Many of these commands may prompt you with an “Are you sure?” type prompt. You can skip this prompt by adding a –confirm parameter. Now, the last step is to remove the .wsp file from the solution store. For that, we’ll use Remove-SPUserSolution. It uses the –Identity and –Url parameters like the other commands. Just pass the name of the solution package along with the URL of the site collection.
Remove-SPUserSolution –Identity SandboxedSolutionProject.wsp –Site http://sp2010/sites/sandbox
Now the solution is gone from the Solutions gallery. I like to automate everything that I can so these simple PowerShell commands should help if you are working with sandboxed solutions.