Friday, June 26, 2015

How to Activate a SharePoint feature using PowerShell or STSADM

To Enable a SharePoint Feature, you must first determine the scope of the feature. If the scope is Web-based or is a site collection scope, the URL parameter is required. However, if the scope is farm-based, the URL parameter is not required.

Syntax - PowerShell

Enable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-PassThru <SwitchParameter>] [-WhatIf [<SwitchParameter>]]

This example enables the "MyCustom" site scoped SharePoint Feature at http://somesite.
Enable-SPFeature -identity "MyCustom" -URL http:// sitename

This example enables all SharePoint Features in the subsite at http://somesite/myweb.
$w = Get-SPWeb http://somesite/myweb | ForEach{ $_.URL }
Get-SPFeature -Web $w |%{ Enable-SPFeature -Identity $_ -URL $w}

Syntax - STSADM

stsadm -o activatefeature
   {-filename <relative path to Feature.xml> | -name <feature folder> | -id <feature ID>}
   [-url] <URL name>
   [-force]

Parameter
Value
Description
filename
A valid file path, such as "MyFeature\Feature.xml"
Path to feature must be a relative path to the 14\Template\Features directory. Can be any standard character that the Windows system supports for a file name.
name
Name of the feature directory, such as “MyFeature”
Name of the feature folder located in the 14\Template\Features directory
id
A valid GUID, e.g.  “11d186e-7306-4902-a825-0eb7609e9280”
GUID that identifies the feature to activate
url
A valid URL, such as http://server_name
URL of the Web application, site collection, or Web site to which the feature is being activated

Note : If you try to use the Url parameter on a farm-scoped feature, you receive the following error message:
The feature ‘<feature name>’ applies to the entire farm; the Url parameter cannot be used with farm-scoped features.

No comments:

Post a Comment