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.

PowerShellAddSPUserSolution

We can now see our .wsp file in the solution gallery.

SolutionGalleryNotActivated

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

PowerShellInstallSPUserSolution

Once activated you can confirm it in the solutions gallery.  You can now activate features as desired (using PowerShell if you want).

SolutionGalleryActivated

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

PowerShellUninstallSPUserSolution

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

PowerShellRemoveSPUserSolution

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.

Comments

# SharePoint Daily » Blog Archive » Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots ‘Too Quickly’

Pingback from  SharePoint Daily  » Blog Archive   » Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots ‘Too Quickly’

# Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots 'Too Quickly'

Wednesday, May 23, 2012 7:58 AM by SharePoint Daily

YAY, the sun is out. - Dooley Top News Stories Whose SharePoint is It Anyway (AIIM) Lately, I’ve

# re: Adding and Deploying Sandboxed Solutions Using PowerShell

Wednesday, December 12, 2012 10:21 AM by Max

I was able to activate solution which includes empty content type definition. But as soon as I add Feature Event Receiver without any code in it (all methods are commented) then this solution fails with the error Install-SPUserSolution : Sandboxed code execution request failed. Could you please help me with this error?

# Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots ‘Too Quickly’ – Bamboo Solutions

Pingback from  Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots ‘Too Quickly’ – Bamboo Solutions

# Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots ‘Too Quickly’ – Bamboo Solutions

Pingback from  Whose SharePoint is It?; Microsoft vs. Google: Social; Windows 8 Boots ‘Too Quickly’ – Bamboo Solutions

Leave a Comment

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