FIX: The parameter Param is declared in parameter-set multiple times

Which parameter is Param and what is ‘AllParameterSets’?

I had a weird error message this week that I haven’t seen before. I ran this script in an Azure DevOps Pipeline so I couldn’t really see what went wrong. It took me a while before I realized exactly what the error message meant.

The exact error message:

The parameter "Param" is declared in parameter-set "__AllParameterSets" multiple times. 

I just want the solution for: The parameter Param is declared in parameter-set __AllParameterSets multiple times

One of your Parameters in your script or function has a double notation for a Parameter attribute with the same name for the ParameterSet attribute.
For example, the $DTAP parameter contained [parameter(mandatory = $true)] twice in my code.

param (
    [parameter(mandatory = $false)]
    $Location = 'West Europe',
    [parameter(mandatory = $false)]
    $TemplateFile = 'json\ARMtemplate.json',
    [parameter(mandatory = $true)]
    [ValidateSet('DryRun','Development', 'Test', 'Accept', 'Production')]
    [parameter(mandatory = $true)]
    $DTAP,
    [parameter(mandatory = $false)]
    $PrefixCode = 'bwitblog'
)

If you don’t define the ParameterSetName, it will be named Param by default. and the Parameter attribute will be seen as the same ParameterSet one variable.


I want the ins and outs for: The parameter Param is declared in parameter-set __AllParameterSets multiple times

The default ParameterSetName is indicated if you don’t specify it in Parameter attribute: [Parameter(ParameterSetName = ‘Example’)].

If I take the above PowerShell as an example, the following values all use the default ParameterSetName: Param.

  • $Location
  • $TemplateFile
  • $DTAP
  • $PrefixCode

Let’s take a closer look at $DTAP.

See the two red circled commas in the screenshot?
The $DTAP Parameter contains everything in between these two commas (also aligned in a green container).

Fix: The parameter Param is declared in parameter-set __AllParameterSets multiple times

Because it contains [Parameter(mandatory = $true)] twice, without the ParameterSetName defined, this is seen as two of the same ParameterSetNames & you therefore get an error.


Reference

For more about ParameterSets please check the official Docs:
about Parameter Sets – PowerShell | Microsoft Docs

For more about Parameter Attributes please check the official Docs:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.1#parameter-attribute

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

One thought on “FIX: The parameter Param is declared in parameter-set multiple times”

  1. I’m not sure how much time I would have spent trying to debug this, but I’m certain you just saved me at least a day. Thank you so much!

Leave a Reply

Your email address will not be published. Required fields are marked *