PoshTip #49 – PSReadLine Module

The PSReadline module contains cmdlets that let you customize the command-line editing environment in Windows PowerShell. The module is a part of PowerShell 5. PSReadLine module extends the PowerShell console features such as:

  • Highlighting syntax
  • Selecting the text
  • Copying and Pasting the text using CTRL+C and CTRL+V

This module is automatically imported when opening the PowerShell console. You can display information about this module:

PS > Get-Module PSReadLine | fl


Name              : PSReadline
Path              : C:\Program Files\WindowsPowerShell\Modules\PSReadline\1.2\PSReadLine.psm1
Description       : Great command line editing in the PowerShell console host
ModuleType        : Script
Version           : 1.2
NestedModules     : {Microsoft.PowerShell.PSReadLine}
ExportedFunctions : PSConsoleHostReadline
ExportedCmdlets   : {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PSReadlineKeyHandler,
                    Set-PSReadlineKeyHandler...}
ExportedVariables :
ExportedAliases   :

You can view the current settings using the following command:

PS > Get-PSReadlineOption


EditMode                               : Windows
ContinuationPrompt                     : >>
ContinuationPromptForegroundColor      : DarkYellow
ContinuationPromptBackgroundColor      : DarkMagenta
ExtraPromptLineCount                   : 0
AddToHistoryHandler                    :
CommandValidationHandler               :
CommandsToValidateScriptBlockArguments : {ForEach-Object, %, Invoke-Command, icm...}
HistoryNoDuplicates                    : False
MaximumHistoryCount                    : 4096
MaximumKillRingCount                   : 10
HistorySearchCursorMovesToEnd          : False
ShowToolTips                           : False
DingTone                               : 1221
CompletionQueryItems                   : 100
WordDelimiters                         : ;:,.[]{}()/\|^&*-=+'"–—―
DingDuration                           : 50
BellStyle                              : Audible
HistorySearchCaseSensitive             : False
ViModeIndicator                        : None
HistorySavePath                        : C:\Users\Nicolas\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\Conso
                                         leHost_history.txt
HistorySaveStyle                       : SaveIncrementally
DefaultTokenForegroundColor            : DarkYellow
CommentForegroundColor                 : DarkGreen
KeywordForegroundColor                 : Green
StringForegroundColor                  : DarkCyan
OperatorForegroundColor                : DarkGray
VariableForegroundColor                : Green
CommandForegroundColor                 : Yellow
ParameterForegroundColor               : DarkGray
TypeForegroundColor                    : Gray
NumberForegroundColor                  : White
MemberForegroundColor                  : White
DefaultTokenBackgroundColor            : DarkMagenta
CommentBackgroundColor                 : DarkMagenta
KeywordBackgroundColor                 : DarkMagenta
StringBackgroundColor                  : DarkMagenta
OperatorBackgroundColor                : DarkMagenta
VariableBackgroundColor                : DarkMagenta
CommandBackgroundColor                 : DarkMagenta
ParameterBackgroundColor               : DarkMagenta
TypeBackgroundColor                    : DarkMagenta
NumberBackgroundColor                  : DarkMagenta
MemberBackgroundColor                  : DarkMagenta
EmphasisForegroundColor                : Cyan
EmphasisBackgroundColor                : DarkMagenta
ErrorForegroundColor                   : Red
ErrorBackgroundColor                   : DarkMagenta

Now, you can change some settings using the Set-PSReadlineOption cmdlet. Below, I want to specify a new value for the “CommentForegroundColor” option:

PS > $options = Get-PSReadlineOption
PS > $options.CommentForegroundColor = "cyan"

Here is an example:

 

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.