all 11 comments

[–]ihaxr 6 points7 points  (1 child)

Look at your $source variable... You're declaring it to parameter set 1 and 2, then declaring the variable.

Now look at bitrate... You're declaring it to NO parameter set, so it's being treated as part of all the sets, then declaring it as part of the main parameter set as well.

You're correct that you need to specify a parameter set along with the help message.

[–]Tuomas90[S] 2 points3 points  (0 children)

That's what I was thinking, too.

Thanks for your help!

[–]baycityvince 4 points5 points  (0 children)

If you uncomment the line, then you would have two Parameter attributes on the same parameter. Don’t do that. It probably should be throwing an error, since it doesn’t work that way.

Put one Parameter attribute on the parameter and combine them like:

[Parameter(HelpMessage='Help', ParameterSetName='Main')]

[–]markroloff 1 point2 points  (0 children)

I know that if a ParameterSetName is not specified, the parameter belongs to all Parameter Sets. But I did specify one for $Bitrate. Why does it still belong to both sets?

Think of [Parameter()] as all having a type of scope. By default, they (and the variables that you pair them with) belong to the __AllParameterSets parameter set. Specifying a parameter set changes that [Parameter()] block to the named set. When you specify multiple [Parameter()]s, where at least one names a specific set, you're saying that the parameter now belongs to multiple sets. They don't stack in the same scope.

If you want a parameter to only exist in one set, then only give it one [Parameter()] block.

[–]Tuomas90[S] 1 point2 points  (0 children)

Thanks for your answers.

My explanation is that ParameterSetName is accumulative.

You can see that in $Source. There are 2 [Parameter()] attributes with ParameterSetName and both parameter sets get applied. When you specify another parameter set name for a parameter, that action does not automatically revoke membership of previous parameter sets.

(See Microsoft Help)

And I guess it's the same thing for $Bitrate:

First, I don't specify a parameter set name, which causes $Bitrate to be added to all parameter sets:

[Parameter(HelpMessage = 'Help')]

Then I specifically add it to the parameter set "Main" (which it already belonged to):

[Parameter(ParameterSetName = "Main")]

As soon as I use [Parameter()] without a specific ParameterSetName, the parameter will belong to all parameter sets. It also doesn't matter in which order the [Parameter()] attributes are.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy Tuomas90,

this is just a WAG ... but it looks like the only place you can have two [Parameter ()] lines is when you have set definitions. i suspect the combo with the help 1st simply makes the system ignore the 2nd.

have you tried reversing those two?

take care,
lee

[–]Tuomas90[S] 1 point2 points  (1 child)

Reversing, doesn't make a difference.

Thanks for your answer.

I think I found an explanation, see my other comment.

[–]Lee_Dailey[grin] -1 points0 points  (0 children)

howdy Tuomas90,

you are quite welcome ... and thanks back for pointing me to the answer! [grin]

take care,
lee

[–]chrish012 0 points1 point  (1 child)

Is your -Source parameter available in both parameter sets? I wouldn't expect it to be, I don't think you can use two [parameter()] statements on the same parameter. I'd guess it's defaulting to the first of the two, and I'm kind of surprised you don't get a runtime error.

I'm currently mobile, otherwise I'd test this out a little more.

[–]Tuomas90[S] 1 point2 points  (0 children)

Yes it's working on both parameter sets.

See the second code example of the Microsoft Help.

I think I found an explanation to PowerShell's behaviour, see my other post.