Last active
March 6, 2017 00:50
-
-
Save mattmcnabb/af49cd9ca760a83543694d46eae9b069 to your computer and use it in GitHub Desktop.
Dynamic Parameter Tab Completion Bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-DynamicParameter | |
{ | |
[CmdletBinding()] | |
PARAM | |
( | |
[string[]] | |
$Param1, | |
# this parameter seems to cause the problem - if I specify [string] then tab-completion works for -DynamicParameter | |
[PSCredential] | |
$Param2 | |
) | |
DYNAMICPARAM | |
{ | |
if ($Param1 -contains "a") | |
{ | |
$Name = "DynamicParameter" | |
$ParamAttr = [System.Management.Automation.ParameterAttribute]::new() | |
$ParamAttr.Mandatory = $true | |
$Attributes = [Collections.ObjectModel.Collection[System.Attribute]]::new() | |
$Attributes.Add($ParamAttr) | |
$Parameter = [System.Management.Automation.RuntimeDefinedParameter]::new($Name, [string], $Attributes) | |
$Dictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() | |
$Dictionary.Add($Name, $Parameter) | |
$Dictionary | |
} | |
} | |
PROCESS | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this works as expected - hitting tab expands the parameter "-DynamicParameter" | |
Test-DynamicParameter -Param1 'a' -<tab> | |
# this fails - hitting tab does nothing. however, the parameter still works if I type it out | |
Test-DynamicParameter -Param1 'a' -Param2 $Credential -<tab> | |
# If I change the type attribute of Param2 to [string] then tab-completion works for the dynamic parameter | |
# Weird! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment