This is a series of 3 blog posts on one of the best kept secrets in PowerShell: “Argument Completion”:
- Building PowerShell auto-completion using TabExpansionPlusPlus – Part 1 – What?
- Building PowerShell auto-completion using TabExpansionPlusPlus – Part 2 – How?
- Building PowerShell auto-completion using TabExpansionPlusPlus – Part 3 – When?
Starting with PowerShell version 3.0, there is excellent support for tab completion/expansion and Intellisense, but it is still missing some useful features.
The PowerShell module TabExpansionPlusPlus addresses some of those shortcomings.
TabExpansionPlusPlus adds support for the following:
What is “Argument Completion”?
When you look at the syntax of PowerShell commands, you should have this syntax:
Verb-<Prefix>Noun –Parameter <argument>
Argument completion will provide a list of relevant arguments for you to choose from and will feed the selected argument value to the parameter.
In other words, it will provide Intellisense auto-completion for parameter arguments in both PowerShell ISE and PowerShell CLI (starting from PowerShell version 5.0).
The bad news
Today, only a very limited set of cmdlets provide this functionality built-in.
For example: Get-Service
The good news
You can build those argument completions your self as part of your PowerShell toolmaking.
This is where the PowerShell module TabExpansionPlusPlus comes in…
In addition to making it simple to add your own custom argument completion, TabExpansionPlusPlus also provides many useful custom argument completers “out of box” for many PowerShell modules.
Those also serve as good examples of how to create/add your own “argument completers”.
Recently, I have also been adding many argument completers for many modules.
Here’s a summary:
Module/Technology | |
|
|
* Argument Completers in progress.
NOTE: You can even build argument completion for external non-PowerShell commands.
How geeky is that .
Here’s an example of argument completion on RoboCopy.exe.
Installation & Usage
If you have PowerShell version 5 or PowerShellGet, you can install right away using
PS> Install-Module TabExpansionPlusPlus
When you import the TabExpansionPlusPlus module, all of the default included argument completer functions will be available to you.
PS> Import-Module TabExpansionPlusPlus
Typically you find all argument completer functions as PowerShell scripts in the folder “C:\Program Files\WindowsPowerShell\Modules\TabExpansionPlusPlus\<version>” following the naming convention “<PSModule>.ArgumentCompleter.ps1” .
However, you can create your own argument completer functions/scripts to auto-complete parameter values for your own PowerShell functions.
NOTE: In the version 1.1 of TabExpansionPlusPlus, all of the argument completers that I have added/written are not (yet) included.
You will need to download or clone the GitHub project here and extract the contents from the zip file.
UPDATE: Version 1.2 has been published by Jason Shirk @lzybkr (creator and owner of the module) which contains all the above described argument completers.
Enjoy
3 thoughts on “Building PowerShell auto-completion using TabExpansionPlusPlus – Part 1 – What?”