The argument-completer attribute

The argument-completer attribute is used much like ValidateScript. The script block used previously is used as an argument for the attribute, shown as follows:

function Test-ArgumentCompleter {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ArgumentCompleter( {
param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter )

$possibleValues = 'Start', 'Stop', 'Create', 'Delete'
$possibleValues | Where-Object { $_ -like "$wordToComplete*" }
} )]
$Action
)
}

When the user types Test-ArgumentCompleter and then presses Tab, the completer offers up each of the possible values with no filtering. If the user were to type Test-ArgumentCompleters, only start and stop would be offered when pressing Tab.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.114.100