Showing posts with label deployment. Show all posts
Showing posts with label deployment. Show all posts

Thursday, 7 February 2013

Upgrade a feature with PowerShell

When you wnat to add new fields to an existing content type in SharePoint you make a new version of the feature - an upgraded version. You deploy the new wsp package with an SPUpdateSolution command.
But you are not done yet! It is only deplyed to the server. You must tell SharePoint explicitly too look for a new version of the feature, and upgrade the feature to this version.
Oddly you cannot do this through the interface - you must do it through code. This can be done in C#, (Visual Basic?), or in PowerShell.

To upgrade a feature in PowerShell you do this:

  • $s = Get-SPSite -Identity 'insert url of the web where the solution is deployed'
  • $features = $s.QueryFeatures('web',$true)
  • foreach($feature in $features){if($feature.DefinitionId -eq ‘72dc4341-4404-413c-b8ab-22e5723fdbec'){$feature.upgrade($true)}}

This will upgrade the feature with id "72dc4341-4404-413c-b8ab-22e5723fdbec".

Wednesday, 21 November 2012

Download/extract deployed wsp packages

When you are about to update a wsp solution it often would be nice to be able to get a backup of the existing.

This is how its done in 3 lines of  PowerShell:

$farm = Get-SPFarm
$file = $farm.Solutions.Item("mysolution.wsp").SolutionFile
$file.SaveAs("c:\Users\sp\Desktop\mysolution.wsp")

You need to be a farm administrator and have permissions to the configuration database.

See also: Extract a WSP Solution from SharePoint 2010