Argument completers
The tab completion system uses argument completers to provide an argument for a parameter when Tab is pressed. For example, the Get-Module
command cycles through module names when Tab is pressed after the command name.
Argument completers have been around in several different forms since PowerShell 2. This section focuses on the implementation of argument completers available in Windows PowerShell 5 and above.
An argument completer does not restrict the values that may be supplied for a parameter. It is used to offer values, to make it easier for an end user to figure out what to enter.
An argument completer is a script block; the script block can expect the following parameters (by position, in the order listed as follows):
commandName
parameterName
wordToComplete
commandAst
fakeBoundParameter
You can use any of these parameters, but the most important and the most frequently used is wordToComplete
.
The...