Intellisense Fails to Resolve ParameterSet if using Switches as Unique Parameter

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"

I wasn’t able to reproduce the problem, using PS v5.0.10586.0 on Windows 10.

Hello Dave,

Thanks for the response. This script was written in PS v4 on Windows 7. However, I validated on PS v5.0.10240.16384 on Windows 10 with the same results. Let me guide you through exactly what I’m doing. Using the code I provided:

Try:

Do-Something -(TAB)

You’ll get an Intellisense drop down.

Try:

Do-Something -DefaultAndAlternate01 -(TAB)

You will NOT get an Intellisense drop down.

Try:

Do-Something -DefaultAndAlternate01:$true -(TAB)

You will get an Intellisense drop down.

It seems with switches, the PowerShell ISE doesn’t try to resolve $PSCmdlet.ParameterSetName until you force it to by using the above Boolean syntax or by typing something along the lines of:

Do-Something -DefaultAndAlternate01 -(BACKSPACE)(DASH)

Does that help you reproduce it?

Nope, still works fine for me. Maybe try launching the ISE with -NoProfile, see if there’s something you’re loading that’s screwing with intellisense?

I’ve figured out the issue. The problem is that I’m moving too fast. If I type the “-” for the next parameter before Intellisense is done running, the drop-down will not show. However, if I wait until the Intellisense icon is gone, THEN type in “-”, it works with no issues.

Now, I did try running PowerShell with the -NoProfile switch, and it did work as expected. But, I though that was strange as I don’t have any actual profile files. What I discovered from that is that Intellisense runs faster when the -NoProfile switch is activated. It was those couple tenths of a second that made the difference.

Thanks for the help, and sorry for posting a non-issue.