DSC WindowsFeatureSet Resource

Applies To: Windows PowerShell 5.x

The WindowsFeatureSet resource in Windows PowerShell Desired State Configuration (DSC) provides a mechanism to ensure that roles and features are added or removed on a target node. This resource is a composite resource that calls the WindowsFeature resource for each feature specified in the Name property.

Use this resource when you want to configure a number of Windows Features to the same state.

Note

This documentation of this DSC resource covers the version that's included with PowerShell prior to version 7.2. The PSDscResources module contains new and updated DSC Resources that are officially supported by Microsoft. The PSDscResources module is available from the PowerShell Gallery.

For more information and updated documentation, see the PSDscResources reference documentation.

Syntax

WindowsFeatureSet [string] #ResourceName
{
    Name = [string[]]
    [ Source = [string] ]
    [ IncludeAllSubFeature = [Boolean] ]
    [ Credential = [PSCredential] ]
    [ LogPath = [string] ]
    [ DependsOn = [string[]] ]
    [ Ensure = [string] { Absent | Present }  ]
    [ PsDscRunAsCredential = [PSCredential] ]
}

Properties

Property Description
Name The names of the roles or features that you want to ensure are added or removed. This is the same as the Name property of the Get-WindowsFeature cmdlet, and not the display name of the roles or features.
Source Indicates the location of the source file to use for installation, if necessary.
IncludeAllSubFeature Set this property to $true to include all required subfeatures with of the features you specify with the Name property.
Credential The credentials to use to add or remove the roles or features.
LogPath The path to a log file where you want the resource provider to log the operation.

Common properties

Property Description
DependsOn Indicates that the configuration of another resource must run before this resource is configured. For example, if the ID of the resource configuration script block that you want to run first is ResourceName and its type is ResourceType, the syntax for using this property is DependsOn = "[ResourceType]ResourceName".
Ensure Indicates whether the roles or features are added. To ensure that the roles or features are added, set this property to Present. To ensure that the roles or features are removed, set the property to Absent. The default value is Present.
PsDscRunAsCredential Sets the credential for running the entire resource as.

Note

The PsDscRunAsCredential common property was added in WMF 5.0 to allow running any DSC resource in the context of other credentials. For more information, see Use Credentials with DSC Resources.

Example

The following configuration ensures that the Web-Server (IIS) and SMTP Server features, and all subfeatures of each, are installed.

configuration FeatureSetTest
{
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node localhost
    {

        WindowsFeatureSet WindowsFeatureSetExample
        {
            Name                    = @("SMTP-Server", "Web-Server")
            Ensure                  = 'Present'
            IncludeAllSubFeature    = $true
        }
    }
}