Building PowerShell auto-completion using TabExpansionPlusPlus – Part 1 – What?

This is a series of 3 blog posts on one of the best kept secrets in PowerShell: “Argument Completion”:

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:

  • Easily add custom argument completion.
  • Complete attribute argument names, e.g. [CmdletBinding(Def -or- [Parameter(
  • Exclude hidden files from results.
  • Easily set options like ‘IgnoreHiddenShares’.

    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:

  • Appx
  • BitsTransfer
  • CimCmdlets
  • DataONTAP*
  • Dism
  • DFSN
  • DFSR
  • DHCPServer
  • DNSClient
  • DNSServer
  • FailoverClusters
  • GroupPolicy
  • Hyper-V
  • ISE
  • Microsoft.PowerShell.LocalAccounts
  • Microsoft.PowerShell.Core
  • Microsoft.PowerShell.Diagnostics
  • Microsoft.PowerShell.Management
  • Microsoft.PowerShell.Utility
  • NetAdapter
  • NetLbfo
  • NetQoS
  • NetSecurity
  • NetTCPIP
  • PowerShellWebAccess
  • PackageManagement
  • PnPDevice
  • PowerShellDirect
  • PowerShellGet
  • PrintManagement
  • ScheduledTasks
  • SmbShare
  • ServerManager
  • VirtualMachineManager*
  • * Argument Completers in progress.

    NOTE: You can even build argument completion for external non-PowerShell commands.
    How geeky is that Winking smile.
    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.

    githubNOTE: 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 Smile

  • Advertisement

    3 thoughts on “Building PowerShell auto-completion using TabExpansionPlusPlus – Part 1 – What?

    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s