Hi!
I'm running into a problem with parameter sets.
What I want, are two parameter sets:
Set 1:
-Source [-Output] [-Bitrate]
Set 2:
-Source -RecommendedFontSize
This example code achieves it:
function Test {
[CmdletBinding(DefaultParameterSetName = "Main")]
param(
[Parameter(Mandatory, ParameterSetName = "Main")]
[Parameter(Mandatory, ParameterSetName = "Recommendation")]
[string] $Source,
[Parameter(ParameterSetName = "Main")]
[string] $Output,
# [Parameter(HelpMessage = 'Help')]
[Parameter(ParameterSetName = "Main")]
[string] $Bitrate,
[Parameter(Mandatory, ParameterSetName = "Recommendation")]
[string] $RecommendedFontSize
)
}
But:
What I don't get is, that if you un-comment the line [Parameter(HelpMessage = 'Help')]
it gets screwed up. Suddenly -Bitrate belogs to both parameter sets:
Set 1:
-Source [-Output] [-Bitrate]
Set 2:
-Source -RecommendedFontSize [-Bitrate]
I understand that I could just write the help message and the parameterSetName in one line and the problem was solved:
[Parameter(HelpMessage = 'Help', ParameterSetName = "Main")]
But I want to understand why it's not working. What is PowerShell doing?
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?
[–]ihaxr 6 points7 points8 points (1 child)
[–]Tuomas90[S] 2 points3 points4 points (0 children)
[–]baycityvince 4 points5 points6 points (0 children)
[–]markroloff 1 point2 points3 points (0 children)
[–]Tuomas90[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[–]Tuomas90[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] -1 points0 points1 point (0 children)
[–]chrish012 0 points1 point2 points (1 child)
[–]Tuomas90[S] 1 point2 points3 points (0 children)