1

This is a script for VS PowerShell.

function global:Add-Shape { param([string]$Shape, [string[]]$Colors) 
    Write-Host "Shape Name:$Shape"

    foreach ($i in $Colors) {
        Write-Host "Color Name:$i"
    }
}

Register-TabExpansion 'Add-Shape' @{
    'Shape' = { 
        "Circle",
        "Square",
        "Triangle"
    }
    'Colors' = { 
        "Brown",
        "Red",
        "Blue"
    }
}

In Package Manager Console When I try this command to run the script and I can use tab to select options and then values for each option from TabExpansion:

Add-Shape -Shape Circle -Colors Red,...

The problem is after selecting first value for array option tab completion never shows again to select additional.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Ali.Asadi
  • 643
  • 10
  • 16

1 Answers1

1

you can use ValidateSet:

function global:Add-Shape { 

    param(
    [ValidateSet("Circle","Square","Triangle")]
    [string]$Shape,
    [ValidateSet("Brown","Red","Blue")]
    [string[]]$Colors
    )
    Write-Host "Shape Name:$Shape"

    foreach ($i in $Colors) {
        Write-Host "Color Name:$i"
    }
}
wallybh
  • 934
  • 1
  • 11
  • 28