Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Last active March 6, 2017 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmcnabb/af49cd9ca760a83543694d46eae9b069 to your computer and use it in GitHub Desktop.
Save mattmcnabb/af49cd9ca760a83543694d46eae9b069 to your computer and use it in GitHub Desktop.
Dynamic Parameter Tab Completion Bug?
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 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