0

I'm using TabExpansion2 in PowerShell 3 and when I tab to complete an argument it brings up the string I want but wrapped in syntax I don't want.

For instance when I hit tab after -binName:

Use-Bin -binName @{Name=5.0}

what I need is:

Use-Bin -binName 5.0

I'm using this script: https://www.powershellgallery.com/packages/PowerShellCookbook/1.3.6/Content/TabExpansion.ps1

with these adjusted options:

$options["CustomArgumentCompleters"] = @{
            "binName" = {Get-ChildItem -Path $global:TH_BinDir | Select-Object Name}
            "dbName" = {Get-ChildItem -Path $global:TH_DBDir\RT5.7\ | Select-Object Name}
            "patchSubDir" ={Get-ChildItem -Path $global:TH_BinDir\Patches\ | Select-Object Name}
            "hmiSubDir" = {Get-ChildItem -Path $global:TH_HMIDir | Select-Object Name}
            "moduleScript" = {Get-ChildItem -Path $global:TH_ModPaths | Select-Object Name}
            "items" = {"bins", "databases", "modules"}           
        }

Thanks!

Matt
  • 45,022
  • 8
  • 78
  • 119
johann_dev
  • 43
  • 4
  • Does the answer at the bottom of [this question](http://stackoverflow.com/questions/30633098/powershell-param-validateset-values-with-spaces-and-tab-completion) help at all? – user4317867 Jun 11 '16 at 01:06

1 Answers1

0

I am not familiar with tabexpansion but your issue is you are returning objects with name properties. You want to return just the strings.

$options["CustomArgumentCompleters"] = @{
    "binName" = {Get-ChildItem -Path $global:TH_BinDir | Select-Object -ExpandProperty Name}
    "dbName" = {Get-ChildItem -Path $global:TH_DBDir\RT5.7\ | Select-Object -ExpandProperty Name}
    "patchSubDir" ={Get-ChildItem -Path $global:TH_BinDir\Patches\ | Select-Object -ExpandProperty Name}
    "hmiSubDir" = {Get-ChildItem -Path $global:TH_HMIDir | Select-Object -ExpandProperty Name}
    "moduleScript" = {Get-ChildItem -Path $global:TH_ModPaths | Select-Object -ExpandProperty Name}
    "items" = {"bins", "databases", "modules"}   
}

Since you are using 3.0 this would be more terse and accomplish the same thing.

$options["CustomArgumentCompleters"] = @{
    "binName" = {(Get-ChildItem -Path $global:TH_BinDir).Name}
    "dbName" = {(Get-ChildItem -Path $global:TH_DBDir\RT5.7\).Name}
    "patchSubDir" ={(Get-ChildItem -Path $global:TH_BinDir\Patches\).Name}
    "hmiSubDir" = {(Get-ChildItem -Path $global:TH_HMIDir).Name}
    "moduleScript" = {(Get-ChildItem -Path $global:TH_ModPaths).Name}
    "items" = {"bins", "databases", "modules"}           
}

Both solutions work by expanding the strings of the single property name.

Matt
  • 45,022
  • 8
  • 78
  • 119