Skip to content

xWindowsOptionalFeatureSet

dscbot edited this page Nov 11, 2023 · 1 revision

xWindowsOptionalFeatureSet

Parameters

Parameter Attribute DataType Description Allowed Values
Name Required System.String[] The names of the Windows optional features to enable or disable.
Ensure Required System.String Specifies whether the features should be enabled or disabled.

To enable a set of features, set this property to Present. To disable a set of features, set this property to Absent. | Present, Absent | | RemoveFilesOnDisable | Write | System.Boolean | Specifies whether or not to remove all files associated with the features when they are disabled. | | | NoWindowsUpdateCheck | Write | System.Boolean | Specifies whether or not DISM should contact Windows Update (WU) when searching for the source files to restore Windows optional features on an online image. | | | LogPath | Write | System.String | The file path to which to log the opertation. | | | LogLevel | Write | System.String | The level of detail to include in the log. | ErrorsOnly, ErrorsAndWarning, ErrorsAndWarningAndInformation |

Description

Provides a mechanism to configure and manage multiple xWindowsOptionalFeature resources on a target node. This resource works on Nano Server.

Requirements

  • Target machine must be running a Windows client operating system, Windows Server 2012 or later, or Nano Server.
  • Target machine must have access to the DISM PowerShell module.

Examples

Example 1

#Requires -Module xPSDesiredStateConfiguration

<#
    .DESCRIPTION
        Enables one or more Windows optional features with the specified name and
        outputs a log to the specified path.

    .PARAMETER Name
        The name of one or more Windows optional features to enable.

    .PARAMETER LogPath
        The path to the file to log the enable operation to.

    .NOTES
        Can only be run on Windows client operating systems and Windows Server 2012 or later.
        The DISM PowerShell module must be available on the target machine.

    .EXAMPLE
        xWindowsOptionalFeatureSet_Enable_Config -Name @('MicrosoftWindowsPowerShellV2', 'Internet-Explorer-Optional-amd64') -LogPath 'c:\log\feature.log'

        Compiles a configuration that enables the Windows optional features
        MicrosoftWindowsPowerShellV2 and Internet-Explorer-Optional-amd64 and
        outputs a log of the operations to a file at the path 'C:\LogPath\Log.txt'.

    .EXAMPLE
        Start-AzureRmAutomationDscCompilationJob -ResourceGroupName '<resource-group>' -AutomationAccountName '<automation-account>' -ConfigurationName 'xWindowsOptionalFeatureSet_EnableConfig' -Parameters @{ Name = @('MicrosoftWindowsPowerShellV2', 'Internet-Explorer-Optional-amd64'); LogPath = 'c:\log\feature.log' }

        Compiles a configuration in Azure Automation that that enables the
        Windows optional features MicrosoftWindowsPowerShellV2 and
        Internet-Explorer-Optional-amd64 and outputs a log of the operations to
        a file at the path 'C:\LogPath\Log.txt'.

        Replace the <resource-group> and <automation-account> with correct values.
#>
Configuration xWindowsOptionalFeatureSet_Enable_Config
{
    param
    (
        [Parameter(Mandatory = $true)]
        [System.String[]]
        $Name,

        [Parameter(Mandatory = $true)]
        [System.String]
        $LogPath
    )

    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    Node localhost
    {
        xWindowsOptionalFeatureSet WindowsOptionalFeatureSet1
        {
            Name    = $Name
            Ensure  = 'Present'
            LogPath = $LogPath
        }
    }
}

Example 2

#Requires -Module xPSDesiredStateConfiguration

<#
    .DESCRIPTION
        Disables one or more Windows optional features with the specified name
        and outputs a log to the specified path.When the optional feature is
        disabled, the files associated with the feature will also be removed.

    .PARAMETER Name
        The name of one or more Windows optional features to disable.

    .PARAMETER LogPath
        The path to the file to log the disable operation to.

    .NOTES
        Can only be run on Windows client operating systems and Windows Server 2012 or later.
        The DISM PowerShell module must be available on the target machine.

    .EXAMPLE
        xWindowsOptionalFeatureSet_Disable_Config -Name @('TelnetClient', 'LegacyComponents') -LogPath 'c:\log\feature.log'

        Compiles a configuration that disables the Windows optional features
        TelnetClient and LegacyComponents and removes all files associated with
        these features. Outputs a log of the operations to a file at the path
        'C:\LogPath\Log.txt'.

    .EXAMPLE
        Start-AzureRmAutomationDscCompilationJob -ResourceGroupName '<resource-group>' -AutomationAccountName '<automation-account>' -ConfigurationName 'xWindowsOptionalFeatureSet_DisableConfig' -Parameters @{ Name = @('TelnetClient', 'LegacyComponents'); LogPath = 'c:\log\feature.log' }

        Compiles a configuration in Azure Automation that that disables the
        Windows optional features TelnetClient and LegacyComponents and removes
        all files associated with these features. Outputs a log of the operations
        to a file at the path 'C:\LogPath\Log.txt'.

        Replace the <resource-group> and <automation-account> with correct values.
#>
Configuration xWindowsOptionalFeatureSet_Disable_Config
{
    param
    (
        [Parameter(Mandatory = $true)]
        [System.String[]]
        $Name,

        [Parameter(Mandatory = $true)]
        [System.String]
        $LogPath
    )

    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    Node localhost
    {
        xWindowsOptionalFeatureSet WindowsOptionalFeatureSet1
        {
            Name                 = $Name
            Ensure               = 'Absent'
            LogPath              = $LogPath
            RemoveFilesOnDisable = $true
        }
    }
}