How to install Sandboxed Solution with Powershell (SharePoint Management Shell)
Farm solutions can be installed with SharePoint Management Shell (PowerShell), but did you know that sandboxed solutions can be too?
The cmdlets have almost the same name as the corresponding cmdlets for farm solutions, the difference being that "User" is inserted after the "SP".
To upload a sandboxed solution to a site collection's Solution Gallery with PowerShell, use the cmdlet Add-SPUserSolution. At a minimum, you need to identify the path to the solution package (wsp file) and the target site collection by using the LiteralPath and Site parameters. Example:
Add-SPUserSolution -LiteralPath c:\CandidateSandboxedSolutions\MySandboxedSolution.wsp -Site http://MyServer/sites/Contoso
Now, of course, you need to deploy the solution, except that when we are talking about sandboxed solutions, this step is called "activation" instead of "deployment". But, between you and me, it is the same thing. (And activating a sandboxed solution is not conceptually the same thing as activating a SharePoint Feature.) To deploy the solution, use the Install-SPUserSoluton cmdlet. At a minimum, you need to identify the solution that you want to deploy and the site collection by using the Identity and Site parameters. Example:
Install-SPUserSolution -Identity MySandboxedSolution.wsp -Site http://MyServer/sites/Contoso
You can reverse the latter step with the Uninstall-SPUserSolution cmdlet with the same two mandatory parameters. You can reverse the first step with the Remove-SPUserSolution cmdlet. It also requires the Identity and Site parameters.
There is also an Update-SPUserSolution cmdlet which is used, of course, to update a solution that has already been "activated" (that is, deployed). The syntax is the same as the Install-SPUserSolution except that you use the Identity parameter to identify the old solution and you use ToSolution parameter to identify the new replacement solution. You must first use the Add-SPUserSolution to upload the new version of the solution to the Solution Gallery. Example:
Add-SPUserSolution -LiteralPath c:\CandidateSandboxedSolutions\MyImprovedSandboxedSolution.wsp -Site http://MyServer/sites/Contoso
Update-SPUserSolution -Identity MySandboxedSolution.wsp -Site http://MyServer/sites/Contoso -ToSolution MyImprovedSandboxedSolution.wsp
There are additional, optional, parameters for all of these cmdlets. For help on any of them, use the Get-Help cmdlet followed by the name of the cmdlet and the "full" parameter. Example:
Get-Help Add-SPUserSolution -full