≡ Menu

Powershell: Get-WindowsOptionaFeature and Enable-WindowsOptionalFeature are failing — Solved

Today I noticed that Get-WindowsOptionalFeature and Enable-WindowsOptionalFeature cmdlets in DISM module of PowerShell V3 are failing with below error.

Get-WindowsOptionalFeature : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Get-WindowsOptionalFeature
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WindowsOptionalFeature], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Dism.Commands.GetWindowsOptionalFeatureCommand

After little research I understood that, DISM module is designed to work with offline images by default. To use them against a online server, we should use-Onlineswitch.

I did that and able to install telnetclient feature without any issues using the below sequence of commands.

Get-WindowsOptionalFeature -Online -FeatureName TelnetClient            
Enable-WindowsOptionalFeature -Online -FeatureName TelnetClient            
Get-WindowsOptionalFeature -Online -FeatureName TelnetClient

The big question that is still left my mind is, “Do I need to do that for every cmdlet in DISM module I use?”. Fortunately, there is a way available to get rid this -Online parameter.

The workaround is to add the online option to default parameters (Source: ITfishihngpole.com).

$PSDefaultParameterValues = @{"*WindowsOptionalFeature:Online"=$true}

After this you can run Get-WindowsOptionalFeature or any other cmdlet in DISM module without -Online option.

PS C:\Users\Administrator> Get-WindowsOptionalFeature -FeatureName telnetClient

Feature Name : TelnetClient
Display Name : Telnet Client
Description : Allows you to connect to other computers remotely.
Restart Required : Possible
State : Disabled
Custom Properties :
ServerComponent\Description : Telnet Client uses the
Telnet protocol to connect to a remote Telnet server and run applications on that server.
ServerComponent\DisplayName : Telnet Client
ServerComponent\Id : 44
ServerComponent\Type : Feature
ServerComponent\UniqueName : Telnet-Client
ServerComponent\Version\Major : 6
ServerComponent\Version\Minor : 2
ServerComponent\Deploys\Update\Name : TelnetClient

PS C:\Users\Administrator>

Hope this helps.

Comments on this entry are closed.

  • Gilbert Palau January 30, 2021, 3:13 am

    I get the error: The term ‘PSDefaultParameterValues’ is not recognized as the name of a cmdlet… etc. This is on Windows Server 2019

    • hater September 8, 2021, 5:56 pm

      I am using Windows server 2019 and the $PSDefaultParameterValues is working fine. Maybe you are missing $ sign in front

  • aenagy December 13, 2021, 1:37 am

    Thanks. That solved my problem.