- OpenVPN IPv6 and IPv4 configuration - Mon, Mar 1 2021
- 4sysops author and member competition 2020 - Fri, Jan 1 2021
- Assign an IPv6 address to an EC2 instance (dual stack) - Tue, Dec 15 2020
The new PowerShell console that comes with Windows 10 offers a range of improvements. The PSReadline module adds new functionality to the console that can increase your productivity when editing PowerShell commands. The module is located in C:\Program Files\WindowsPowerShell\Modules and is imported automatically when you launch a PowerShell console.
Syntax highlighting is one of the features that the module brings to the PowerShell 5 console:
This improves readability and reduces the risk of syntax errors. PSReadline can also detect some syntax errors. You will see a red greater-than sign at the end of the prompt:
However, this doesn’t work for all syntax errors. In contrast to the previous PSReadline, the PowerShell 5 version doesn’t prevent you from executing commands that contain syntax errors.
If you often copy and paste text in the console, you will like that the console now behaves like any other Windows application. That is, you can highlight text with the cursor keys while pressing the SHIFT keys. You can then copy the text with CTRL+C and paste with CTRL+V. It is hard to believe, but this wasn’t possible in Windows 8.1 and PowerShell 4.
Selecting text on the PowerShell 5 console
Of course, you can also use the mouse to highlight text. The old way (highlighting text as a block) is gone. If you are editing a command that has multiple lines, you have to use the left and right cursor keys. Up-arrow and down-arrow don’t work.
You can start a new line by pressing SHIFT+ENTER.
One of my favorite features of the PSReadline module is the history search. To search backward, you have to press CTRL+R; to search forward, CTRL+S.
As you can see in the screenshot, the module also finds text in the middle of a command and not just at the beginning. This history is still available if you close the console. If you open a second a console, the history of the first console is immediately available.
Useful is menu completion that presents a list of options when you press CTRL+SPACE. When you switch to Emacs mode, you can also work with bash-style TAB completion. The following command changes your console to Emacs mode:
Set-PSReadlineOption -EditMode Emacs
If you now start entering a command and press the TAB key, you will get a list of possible options.
To view all key bindings in Emacs mode, you can use the following command:
To switch back to Windows mode, you need the next command:
Set-PSReadlineOption -EditMode Windows
You can also change key bindings. For instance, if you just like the bash-style auto-completion in Windows mode, the following command changes the key binding accordingly:
Set-PSReadlineKeyHandler -Key Tab -Function Complete
PSReadline offers a variety of settings that you can change with the next command:
With the Get-Help cmdlet, you can learn more about the module:
You can also disable the module by removing it:
If you don’t like the module, you can just delete it in C:\Program Files\WindowsPowerShell\Modules. Make sure that no PowerShell console is open when you delete the module. You might want to create a copy of the module first. You can then restore it later if you change your mind.