Sunday, December 12, 2010

Install/Uninstall User Solution Application Wide

Build on this blog post on how to get sandboxed on the farm, I also need to be able to install/uninstall sandboxed solution farm wide. There for I made they have two functions to wrap the install and Uninstall-SPUserSolution SPUserSolution.

The core code is when a call (a version 2) of the Get-UserSolution filter to get the deactiveated solutions and then call the build-in cmdlet Install-SPUserSolution

  1. $gc = Start-SPAssignment
  2. Get-UserSolution -SiteCollection $SiteCollection -Filter $Filter -Verboses:$Verboses | `
  3. Where-Object -FilterScript { $_.Status -eq "Deactivated" } | `
  4. Install-SPUserSolution -Site $SiteCollection -AssignmentCollection $gc
  5. Stop-SPAssignment $gc


The code:

Get sandboxed solution on the farm

How to get all sandboxed (user solution) installed on the SharePoint farm.

  1. $gc = Start-SPAssignment
  2. $gc | Get-SPSite | Get-SPUserSolution
  3. Stop-SPAssignment $gc


The output:



Name                                SolutionId                                                      Status

----                                     ----------                                                         ------


Contacts.wsp                   3089ef04-527e-4b35-a0a2-af5f4df8a71b     Activated


Sandboxed1.wsp              a9240922-c794-433c-acf7-0ce7863b46d0 Deactivated


Sandboxed1.1.wsp           a9240922-c794-433c-acf7-0ce7863b46d0 Activated


Sandboxed1.1.wsp           a9240922-c794-433c-acf7-0ce7863b46d0 Activated


Sandboxed1.2.wsp           a9240922-c794-433c-acf7-0ce7863b46d0 Deactivated


Sandboxed1.wsp              a9240922-c794-433c-acf7-0ce7863b46d0 Activated



It is really simple to get a full list of sandboxed solutions, but the output is not useful, because we can see which site collection the sandboxed solution is store in.



This small PowerShell script will display the site collection url



  1. function Get-UserSolution
  2. {
  3. param(
  4. [Parameter(
  5. Position=0,
  6. Mandatory=$true,
  7. ValueFromPipeline=$true,
  8. ValueFromPipelineByPropertyName=$true)
  9. ]
  10. $SiteCollection
  11. )
  12. process
  13. {
  14. Write-host "Site Collection:" $SiteCollection.Url
  15. $gc = Start-SPAssignment
  16. $SiteCollection | Get-SPUserSolution -AssignmentCollection $gc
  17. Stop-SPAssignment $gc
  18. }
  19. }
  20. Get-SPSite | Get-UserSolution


The output:



Site Collection: http://win-ugka6ujlm21



Name                               SolutionId                                                       Status               
----                                    ----------                                                          ------               
Contacts.wsp                   3089ef04-527e-4b35-a0a2-af5f4df8a71b     Activated            
Sandboxed1.wsp              a9240922-c794-433c-acf7-0ce7863b46d0 Deactivated          
Sandboxed1.1.wsp           a9240922-c794-433c-acf7-0ce7863b46d0 Activated            
Sandboxed1.1.wsp           a9240922-c794-433c-acf7-0ce7863b46d0 Activated            
Sandboxed1.2.wsp           a9240922-c794-433c-acf7-0ce7863b46d0 Deactivated          
Site Collection: http://win-ugka6ujlm21/my


Site Collection: http://win-ugka6ujlm21/sites/sandbox


Sandboxed1.wsp              a9240922-c794-433c-acf7-0ce7863b46d0 Activated  



The code: