Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8558701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:52:18+00:00 2026-06-11T15:52:18+00:00

I have this PowerShell cmdlet: function Test-ParameterBinding { # # .SYNOPSIS # Tests parameter

  • 0

I have this PowerShell cmdlet:

function Test-ParameterBinding {
    #
    # .SYNOPSIS
    # Tests parameter binding.
    #
    [CmdletBinding()]
    param (    

        [Parameter(ParameterSetName = 's1', Mandatory = $true)]
        [int] $P1,

        [Parameter(ParameterSetName = 's1')]
        [Parameter(ParameterSetName = 's2', Mandatory = $true)]
        [string] $P2,

        [Parameter(ParameterSetName = 's1')]
        [Parameter(ParameterSetName = 's3', Mandatory = $true)]
        [bool] $P3
    )
    process { $PSCmdlet }
}

And here is the help for this cmdlet:

SYNTAX
    Test-ParameterBinding -P1 <Int32> [-P2 <String>] [-P3 <Boolean>] [<Com…

    Test-ParameterBinding -P2 <String> [<CommonParameters>]

    Test-ParameterBinding -P3 <Boolean> [<CommonParameters>]

Looking at the code and help I would think I could use the cmdlet like this:

Test-ParameterBinding -P2 'Bind to param set s2'
Test-ParameterBinding -P3 $true # Bind to param set s3

But for both of these I get:

Parameter set cannot be resolved using the specified named parameters.

Question 1: Should PowerShell be able to bind to parameter sets s2 and s3 in my two cases?

That means that there was not time to implement it for version 2 of PowerShell, or they did not uncover this issue.

Question 2: Is there something wrong with my reasoning here? Should parameter binding fail in these cases?


I found something that may be directly related to my issue here in the PowerShell documentation:

There is one case where Windows PowerShell cannot use the default parameter set even if a default parameter set name is specified. The Windows PowerShell runtime cannot distinguish between parameter sets based solely on object type. For example, if you have one parameter set that takes a takes a string as the file path, and another set that takes a FileInfo object directly, Windows PowerShell cannot determine which parameter set to use based on the values passed to the cmdlet, nor does it use the default parameter set. In this case, even if you specify a default parameter set name, Windows PowerShell throws an ambiguous parameter set error message.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:52:20+00:00Added an answer on June 11, 2026 at 3:52 pm

    Your logic is correct, Powershell should be able to figure out the parameter set based on your function definition and example usages.

    Apparently Powershell v2 simply did not have robust enough logic for this. It works as expected in Powershell v3, though, which is further confirmation that it’s a shortcoming/bug in v2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a powershell cmdlet, and I can't seem to get the parameter sets
I have a Powershell script file called ExecutBizTalkAppMSI.ps1 This contains a single function called
In PowerShell 1.0, if I have a cmdlet parameter of an enum type, what
I almost have this Powershell script completed but I am stuck at the last
Does PowerShell have an equivalent to this command construct from sh (and derivatives): $
I have a call to powershell.exe that looks like this, and which works from
I have developed a Powershell script that needs to be run automatically daily. This
I'm a beginner in powershell and know C# pretty well. I have this command
I want to execute a powershell using the .net Powershell SDK. I have this
I have a PowerShell script cmdlet that supports the -WhatIf & -Confirm parameters. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.