Home > PowerShell, SharePoint 2010 > Delete Orphaned Sandbox Solutions in SharePoint 2010 Using PowerShell

Delete Orphaned Sandbox Solutions in SharePoint 2010 Using PowerShell

I recently ran into a issue where I had some deleted sandbox solutions in my SharePoint 2010 environment become orphaned. These sandbox solutions even though deleted from the Solution gallery still had a referenced GUID in the Site Collection database as if the soltuion was still there. While there was still a reference to this Solution GUID SharePoint still saw this solution as being available and the option to select this solution as a Site Template was still available, which will throw a Correlation ID when trying to create a new Site with this solution.

To completely remove Orphaned Sandbox Solutions from SharePoint 2010 so the option to select the template is no longer an option follow the PS script below.

—————————————————————————————————————————
$templateTitle = “NAME OF TEMPLATE” #Name of the Sandbox Solution or Template that is Orphaned
$site = Get-SPSite “URL OF SITE WHERE SANDBOX SOLUTION WAS DEPLOYED AND THEN DELETED”
$templates = $site.GetWebTemplates(1033) #Search all site Templates in English (1033)
$badTemplate = $tempaltes | Where {$_.Title -eq $templateTitle} #Find the orphaned Template

#Once orphaned Template is located, delete
if ($badTemplate -ne $null)
{
$id = $badTemplate.Name.Substring(0, $badTemplate.Name.IndexOf(“#”))
$badId = [System.Guid]($id)
$site.Features.Remove($badId)
}
$site.Dispose()
}
—————————————————————————————————————————

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: