Change PowerShell’s Tab Complete

Introducing PSReadline

Have you ever hit tab after Get-AD looking for Get-ADUser ending up with Get-ADAccountAuthorizationGroup instead? Wish tab completion in PowerShell acted more like Bash? Thanks to one of the cmdlets in The PSReadline Module available in PowerShell 5+ now you can come close.

The PSReadline module contains cmdlets that let you customize and tweak the command-line environment in Windows PowerShell. To modify tab completion behaviour we need to use Set-PSReadlineKeyHandler to change the function assigned to the tab key.

Changing Tab Completion

For an experience that closely mirrors Bash the “Complete” function is the way to go.

The tab completion behaviour with the “Complete” function will complete to a point where it could be one of many cmdlets and then show the list of potential cmdlets if you press tab a few times. It is even possible to make the list navigable using the function “MenuComplete” instead.

Here I typed Get-C followed by tab and it allows me to navigate the list of completion options with my arrows keys.

My Setup

My personal preference is to use “Complete” with one of the options of Set-PSReadlineOption.

The combination of “Complete” with -ShowToolTips is similar to the normal “Complete” behaviour but provides Intellisense like tool tips when tab completing cmdlets or parameters.

The “Complete” function with PSReadline ShowToolTips.

Make it Permanent

To make your tab completion options persistent you will need to add them to your profile.

  1. Start by opening your profile in ISE:  PS C:\> ISE $Profile
  2. Add your Set-PSReadlineKeyHandler and optional Set-PSReadlineOption commands to the bottom of the file (each on their own line.)
  3. Press Ctrl+S to save the file and then close ISE.

Now every time you open PowerShell it will tab complete the way you prefer.

More on Profiles

Leave a Reply

Your email address will not be published. Required fields are marked *