Hello All,
I think I may have found a bug/feature, but I’m not sure. I’m building a function that has 4 parameter sets. What I’ve found is that if the Uniqueness of those Parameter sets comes from Switch Parameters, Intellisense will not resolve the ParameterSetName. The PowerShell function itself runs fine and is running the expected Parameter Set.
This causes issues when scripting in the ISE, as Parameter Tab Expansion is not working, unless you force the Switch Parameter to “-Parameter $true” (which will then cause the function to fail because it thinks “$true” is another parameter name) or if you use boolean notation,“-Parameter:$true”, like so:
Do-Something -OnlyAlternate01:$true -
Here’s an example of code I wrote that shows the issue. Everything works as expected, except the -Protocol parameter won’t be listed by intellisense if you run any of the functions as shown below followed by a “-”.
Thoughts?
function Do-Something { [CmdletBinding(DefaultParameterSetName='Default')] Param( [Parameter(ParameterSetName='Default')] [Parameter(ParameterSetName='Alternate01')] [switch]$DefaultAndAlternate01 = $true, [Parameter(ParameterSetName='Alternate01')] [switch]$OnlyAlternate01 = $true, [Parameter(ParameterSetName='Default')] [Parameter(ParameterSetName='Alternate02')] [switch]$DefaultAndAlternate02 = $true, [Parameter(ParameterSetName='Alternate02')] [switch]$OnlyAlternate02 = $true, [System.Net.Sockets.ProtocolType]$Protocol ) Write-Output $PSCmdlet.ParameterSetName } cls Write-Output "Results`n" Write-Output 'Do-Something -DefaultAndAlternate01' Write-Output 'Expected: Default' Write-Output "Result: $(Do-Something -DefaultAndAlternate01)" Write-Output "`n" Write-Output 'Do-Something -DefaultAndAlternate01 -OnlyAlternate01' Write-Output 'Expected: Alternate01' Write-Output "Result: $(Do-Something -DefaultAndAlternate01 -OnlyAlternate01)" Write-Output "`n" Write-Output 'Do-Something -DefaultAndAlternate02' Write-Output 'Expected: Default' Write-Output "Result: $(Do-Something -DefaultAndAlternate02)" Write-Output "`n" Write-Output 'Do-Something -DefaultAndAlternate02 -OnlyAlternate02' Write-Output 'Expected: Alternate02' Write-Output "Result: $(Do-Something -DefaultAndAlternate02 -OnlyAlternate02)" Write-Output "`n"