Skip to content

SPFeature

dscbot edited this page Mar 17, 2023 · 18 revisions

SPFeature

Parameters

Parameter Attribute DataType Description Allowed Values
Name Key String The name of the feature
FeatureScope Required String The scope to change the feature at - Farm, WebApplication, SiteCollection or Site Farm, WebApplication, Site, Web
Url Key String The URL to change the feature at
Ensure Write String Present if the feature is to be enabled, Absent if it is to be disabled Present, Absent
Version Write String The version of the feature to check against

Description

Type: Distributed Requires CredSSP: No

This resource is used to make sure that a specific feature is either enabled or disabled at a given URL/scope. The Ensure property will dictate if the feature should be on or off. The name property is the name of the feature based on its folder name in the FEATURES folder in the SharePoint hive

The default value for the Ensure parameter is Present. When not specifying this parameter, the feature is enabled.

Examples

Example 1

This example shows how to enable a site collection scoped feature

Configuration Example
{
    param
    (
        [Parameter(Mandatory = $true)]
        [PSCredential]
        $SetupAccount
    )

    Import-DscResource -ModuleName SharePointDsc

    node localhost
    {
        SPFeature EnableViewFormsLockDown
        {
            Name                 = "ViewFormPagesLockDown"
            Url                  = "http://www.contoso.com"
            FeatureScope         = "Site"
            Version              = "1.0.0.0"
            PsDscRunAsCredential = $SetupAccount
        }
    }
}

Example 2

This example shows how to disable a site collection scoped feature

    Configuration Example
    {
        param
        (
            [Parameter(Mandatory = $true)]
            [PSCredential]
            $SetupAccount
        )

        Import-DscResource -ModuleName SharePointDsc

        node localhost
        {
            SPFeature EnableViewFormsLockDown
            {
                Name                 = "ViewFormPagesLockDown"
                Url                  = "http://www.contoso.com"
                FeatureScope         = "Site"
                Ensure               = "Absent"
                Version              = "1.0.0.0"
                PsDscRunAsCredential = $SetupAccount
            }
        }
    }
Clone this wiki locally