3

#PSTip Using Tab completion against the command history

Note: This tip requires PowerShell 2.0 or above.

Each time you execute a command in Windows PowerShell, the command is remembered and can be fetched by using the Get-History cmdlet or by using the the up/down arrow keys.  One great, less-known, time-saver feature, allows you to quickly cycle through commands using tab completion. For example, to recall the first command containing the string ‘dir’, type the ‘#’ sign followed by the pattern of the command you want to find, and then press the Tab key:

PS> #dir<TAB>

You should now see the expansion of the first command from your history that matches the pattern.
Keep pressing the TAB key to cycle through all commands that match the specified pattern.

If you know the exact command ID you can quickly retrieve it by specifying the ‘#’ sign followed by the ID:

PS> #11<TAB>
Filed in: Columns, Tips and Tricks Tags: , ,

3 Responses to "#PSTip Using Tab completion against the command history"

  1. Francois-Xavier Cat says:

    Wow that’s awesome! Thanks Shay

  2. Greg Bray says:

    WOW… how have I never seen this before!

  3. Jon Gross says:

    Both f7 and f8 work in the powershell command processor.

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: