Using autocomplete with PowerShell

I. Introduction

In this chapter, we'll look at the principle of autocompletion, which we can benefit from with PowerShell via IntelliSense, a set of features designed to make code writing easier. We can take advantage of this in the two Microsoft code editors: Visual Studio Code and Windows PowerShell ISE.

II. What is autocomplete?

If you're not familiar with the term autocomplete, you should know that it's a feature that allows the computer to predict what you're going to type next, based on what you've already typed. There are two enormous advantages to using autocomplete: it saves you an enormous amount of time and reduces typing errors.

Although we're talking about autocompletion in the context of PowerShell in this chapter, it's important to remember that it's a widespread feature that we can benefit from in other languages and applications. For example, when writing an e-mail in Gmail, autocompletion is available. Recently, we can also benefit from autocompletion when composing a WhatsApp message.

III. Autocompletion with PowerShell

Using autocomplete with PowerShell will help you be more efficient when entering cmdlet names, parameter names, or when calling a variable.

For example, suppose you want to type the cmdlet name "Get-Process". Instead of the full command name, you can simply type "Get-Pro" and then press the tab key. PowerShell will automatically complete the rest of the command for you, to indicate "Get-Process". This avoids typing errors, as PowerShell will complete with a valid command name, whereas if you write the name yourself, you can quickly make a mistake: "Get-Proecss", for example.

In Visual Studio Code, autocompletion even displays the available results as you enter a command, variable name, etc.

PowerShell - VSCode autocompletion

I encourage you to get into the habit of using autocomplete, which is particularly useful if you can't remember the exact syntax of a command. Indeed, the names of some cmdlets are very long and not always easy to remember.

PowerShell autocompletion is not limited to command names, variables, etc... Since it also works with file and directory names! This invaluable aid will help you avoid common syntax errors.

IV. Conclusion

In conclusion, we can say that autocomplete will save you time and increase your efficiency, which will ultimately make using PowerShell much more pleasant and writing code "less cumbersome". So don't hesitate to use it as much as possible!


book to learn PowerShell