Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-BoxStarterTaskbarOptions - Parameter set cannot be resolved using the specified named parameters. #458

Open
veleek opened this issue Nov 19, 2020 · 1 comment
Assignees
Labels
0 - Backlog Issue is accepted, but is not ready to be worked on or not in current sprint Bug Issues where something has happened which was not expected or intended
Milestone

Comments

@veleek
Copy link

veleek commented Nov 19, 2020

What You Are Seeing?

Set-BoxStarterTaskbarOptions uses Parameter Sets to enforce mutually exclusive parameters e.g.:

        [Parameter(ParameterSetName='AlwaysShowIconsOn')]
        [switch]
        $AlwaysShowIconsOn,

        [Parameter(ParameterSetName='AlwaysShowIconsOff')]
        [switch]
        $AlwaysShowIconsOff,

        [Parameter(ParameterSetName='MultiMonitorOff')]
        [switch]
        $MultiMonitorOff,

        [Parameter(ParameterSetName='MultiMonitorOn')]
        [switch]
        $MultiMonitorOn,

However, Powershell enforces that the provided arguments MUST conform to a SINGLE parameter set, so for the above parameters you can't provide AlwaysShowIconsOn AND MultiMonitorOff in the same command because there's no ParameterSet that supports both values.

To resolve this, MultiMonitorOff (and all other params) would need to include parameter set names allowing it to be included the other parameter sets e.g.

        [Parameter(ParameterSetName='MultiMonitorOff')]
        [Parameter(ParameterSetName='AlwaysShowIconsOn')]
        [Parameter(ParameterSetName='AlwaysShowIconsOff')]
        [switch]
        $MultiMonitorOff,

Unfortunately, this makes it possible to provide conflicting values.

Long story short, it's not easy to enforce multiple mutually exclusive parameter sets in a powershell function. Better to just enforce it in the implementation.

Of note is the fact that the second example doesn't work for me.

What Is Expected?

Any set of valid arguments should be accepted.

How Did You Get This To Happen? (Steps to Reproduce)

Set-BoxstarterTaskbarOptions -Combine Never -AlwaysShowIconsOn -MultiMonitorOn -MultiMonitorMode All -MultiMonitorCombine Never

Output Log

Set-BoxstarterTaskbarOptions : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Set-BoxstarterTaskbarOptions -Combine Never -AlwaysShowIconsOn -Multi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-BoxstarterTaskbarOptions], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Set-BoxstarterTaskbarOptions
@veleek veleek added the Bug Issues where something has happened which was not expected or intended label Nov 19, 2020
@pauby pauby added the 0 - Backlog Issue is accepted, but is not ready to be worked on or not in current sprint label Nov 20, 2020
@mwallner mwallner self-assigned this Apr 12, 2022
@mwallner mwallner added this to the 3.0.1 milestone Apr 12, 2022
@mwallner mwallner modified the milestones: 3.0.1, 3.1.0 Nov 17, 2022
@mwallner mwallner modified the milestones: 3.1, 3.2 Jun 6, 2023
@mwallner mwallner modified the milestones: 3.2.0, 3.1.0 Dec 21, 2023
@SvendK
Copy link

SvendK commented Apr 8, 2024

I have just spent an hour debugging my code and have now learned about ParameterSets in Powershell. I just get the "Parameter set cannot be resolved using the specified named parameters." error.

I find it weird the PowerShell don't throw a better error. It is defined what parameters are required for each parameterset, so it should be able to tell me that I need to provide the other parameter(s).

Nevertheless, it doesn't. Would it be possible to

  1. Add to the help section which parameters requires which other parameters.
  2. Maybe somehow provide a better error message on behalf of PowerShell? (I guess that is not possible as the script fails before it gets to the body of the function)

Also, parameters EnableSearchBox and DisableSearchBox are not documented in the help.

I'd make a pull request if I could figure out how :>D

Best regards
SvendK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 - Backlog Issue is accepted, but is not ready to be worked on or not in current sprint Bug Issues where something has happened which was not expected or intended
Projects
None yet
Development

No branches or pull requests

4 participants