Wednesday, February 13, 2013

Export Solution Packages (WSP) from SharePoint farm using PowerShell

When we deploy an updated version of a solution package, it’s better to take a backup of the currently deployed version. Although we can build the appropriate version from the version controlling system if there any, it’s always safer to get the current working solution package which is proven working in that environment.

Following script extracts a set of solution packages you wish to download from the farm.

  1. $packages = @("solution1.wsp","solution2.wsp")
  2. $solutionPath = "C:\Backup\"
  4. foreach ($solution in (Get-SPFarm).Solutions)
  5. {
  6.      if($packages -contains $solution.Name)
  7.      {
  8.          $filename = $Solution.SolutionFile.Name
  9.          $solution.SolutionFile.SaveAs($solutionPath + $filename)
  10.      }    
  11. }

Monday, February 11, 2013

Delete corrupted site collections in SharePoint

When I try to get a list of all the site collection in a SharePoint web application, the script throws an exception stating that it can’t find a specific site collection.

I went to the central administration to check if that site collection exist. It shows the site collection but all other information (e.g Content database, etc..) were empty. Since I don’t need the site I decided to delete that. But I couldn’t delete the site using central administration.

I tried to use the well known PowerShell cmdlet Delete-SPSite which throws a com error <nativehr>0x80070003</nativehr>


Following PowerShell script was successful in deleting the site

$site = Get-SPSite http://sp2013/sites/19014
$id = $site.Id
$contendDb = $site.ContentDatabase 
$contendDb.ForceDeleteSite($id, $false, $false)

You can get more information on ForceDeleteSite command from this Url