How-to: Tab Completion in PowerShell

Command completion when working at the PowerShell prompt.
The [TAB] key can be used to automatically complete cmdlets, Filenames, Variable names and Parameters:

Examples -

Cmdlets:

PS C:\> get-c [tab] [tab] [tab]...

Files:

PS C:\> dir "C:\WINDOWS\system32\ [tab] [tab] [tab]...
PS C:\> Get-Content -path C:\ [tab] [tab] [tab]...

Note this will not complete any folder names which have the 'hidden' attribute set

Variables:

PS C:\> $t [tab] => $true

PS C:\> $m [tab] [tab] [tab]...

Parameters:

PS C:\> gci -f [tab] [tab] [tab]...

PS C:\> Get-Content -Cr [tab]...

Tab completions can be customised with a user-definable function, in PowerShell 2.0 $function:tabexpansion, in PowerShell 3.0 and above $function:tabexpansion2

View the default Tab Expansion function or save it to a text file so you can edit it:

PS C:\> $function:tabexpansion2

PS C:\> $function:tabexpansion2 >tabex.txt

“Everything you need you already have. You are complete right now, you are a whole, total person, not an apprentice person on the way to someplace else” ~ Wayne Dyer

Related PowerShell Cmdlets

Comments and Tab-Expansion
Get-Command - Get basic information about cmdlets.


 
Copyright © 1999-2024 SS64.com
Some rights reserved