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".

No comments:

Post a Comment