Getting to Know Tab Expansion

Sometimes, we all forget vital parts of code and may not have the necessary time or resources to look back or even to write down what we previously have done! That's where tab expansion comes in the picture. In this tutorial, you will learn how tab expansions work and how to work with them.

Setup

If you have not already done so, click open Windows PowerShell ISE. Think of two programs that you use the most. For the purpose of writing this tutorial, notepad and internet explorer are selected.

Step one.

Tab expansion happens when you enter the partial name of a command, file, and then press the Tab key to automatically complete it for you. You can use Tab expansion to expand a path that you've started to enter in the prompt. If you are in the C: drive, there is an easy way to do this:

Type CD WIN then press the Tab key.

Immediately after WINDOWS type \SYS and press Tab again

C:\Windows\System isn't what you need, keep pressing Tab until it says C:\Windows\System32

Now you can press Enter to execute the command and change to that directory.

Expanding commands save time and helps remember the entire command rather than part of it. It simply makes life easier.

Step two.

In the case that you want to export aliases, say you forgot that the command is Export-Alias, you can open up a command shell, type in Export-, and then press the Tab key. Every time the Tab key is pressed it shows the next command that starts with the pattern you provided.
You may also use Tab expansion to display available properties or functions of a given object.

Remarks last but not least…

Tab expansion can be quite useful at times, especially when trying to short hand everything and letting the system complete the rest for you. It's not lazy, it's resourceful! Just keep in mind that in PowerShell, anything is possible! Join us next time for additional Windows PowerShell tutorials! Till then…