Summary: Microsoft Scripting Guy, Ed Wilson, presents a tip from the Charlotte User Group meeting about using PSReadLine.
Microsoft Scripting Guy, Ed Wilson, is here. One really big tip that came out during the Charlotte User Group meeting was to use the PSReadLine module. It provides is syntax highlighting, which makes it easier to understand commands and spot errors because I can see how Windows PowerShell is interpreting something. For example, in the following image, the cmdlet is colored yellow, parameters are gray, variables are green, and the output is white.
If I am trying to run a command and it keeps failing, I can easily spot that I left out a hyphen (for example). The following image shows that the command failed. I can immediately see that Windows PowerShell thinks FileVersionInfo is text, not a parameter (because it is white, not gray). This color coding is actually easier to understand than the error message “A positional parameter cannot be found that accepts argument FileVersionInfo.”
The first thing I need to do is to install PSReadLine. I talk about this in the Hey, Scripting Guy! Blog post The Search for a Better PowerShell Console Experience.
Note If I install PSGet first, I can easily use the Install-Module cmdlet to install PsReadLine. In addition, I can use the Update-Module cmdlet to update the version easily. If I do not use PSGet to do the installation, I will not be able to use Update-Module to do the update.
One thing I like about PSReadline is the enumeration of command options. For example, if I type a .NET class in square brackets, and I press CTRL plus Spacebar, it will list possible command completion options. I can then tab between the options to select the one I need. This is shown here where I am looking for static members of arrays:
One of the things that PSReadLine excels at is making the command-line editing experience much richer. I talk about this in the Hey, Scripting Guy! Blog post A Better PowerShell Command-Line Edit. This post has a couple of tables that detail the options and short-cut key bindings that exist. I also provide a short video that illustrates an edit session in Windows PowerShell by using PSReadLine.
I have written a number of Hey, Scripting Guy! Blog posts about working with Windows PowerShell history, but the PSReadLine module provides a rich command history experience. I wrote about PSReadLine history in Better PowerShell History Management with PSReadLine.
I also documented a number of useful shortcuts that are available in PSReadLine in Useful Shortcuts from PSReadLine PowerShell Module.
PSReadLine is extremely flexible, and it permits me to work the way I want to. One way that it becomes even more useful, is because it is completely customizable. I wrote about customizing PSReadLine in the A Better PowerShell Console with Custom PSReadLine Functions.
That is all there is to using the PSReadLine module. PowerShell Tips and Tricks Week will continue tomorrow when I will talk about more way cool stuff.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy