PSReadline 2.0 not working on Windows 10 1809

  • Context:

I’m running a Windows 10 1809 at home and encountered something weird about PSReadline.
You know PSReadline is the module from Jason Shirk that enables great command line editing in the PowerShell console host.
It maintains an history of commands accross consoles and the ability to search the history (it works using CTRL+R, the same way a Bash shell works), and much more!

  • Issue:

As you can see below in the picture. I’m running a En-US input language with a french keybord layout.
The module version 2.0 that shipped in Windows is loaded but the history isn’t maintained. That’s why I cannot search the history and invoke the following method although the class exists:

[Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems()

NB: This method only exist in version 2.0. It does not exist in version 1.2 that shipped in Windows 10 1803.
It throws the following error:
“The type initializer for ‘Microsoft.PowerShell.PSConsoleReadLine’ threw an exception.”

  • Solution:

I had a look at the issues on GitHub and I’m not the first one who noticed this issue.

Because Jason wrote the following https://github.com/lzybkr/PSReadLine/pull/831 , I went this route:

If you’d rather not use PsGet, you can just download the file PSReadLine.zip and extract the contents into your C:\Users\[User]\Documents\WindowsPowerShell\modules\PSReadLine folder. (You may have to create these directories if they don’t exist.)

I also needed to modify the Execution policy:

Note that if you’ve an Application Control solution, nothing is signed digitally:

if (-not(Test-Path -Path ~\Documents\WindowsPowerShell\modules -PathType Container)) {
md ~\Documents\WindowsPowerShell\modules
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$HT = @{
Uri = 'https://github.com/lzybkr/PSReadLine/releases/download/Latest/PSReadLine.zip'
OutFile = "~/Downloads/PSReadLine.zip"
UseBasicParsing = [switch]::Present
Verbose = [switch]::Present
}
Invoke-WebRequest @HT
$HT = @{
Path = "~/Downloads/PSReadLine.zip"
DestinationPath = "~\Documents\WindowsPowerShell\modules\PSReadLine"
Force = [switch]::Present
Verbose = [switch]::Present
}
Expand-Archive @HT
dir ~\Documents\WindowsPowerShell\modules\PSReadline |
Unblock-File -Verbose
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Verbose -Force
  • Caveat

The above solution works in a admin console, the command history is maintained and is searchable 🙂
But it still doesn’t work with a filtered admin token in a non-admin console 😦

1 thought on “PSReadline 2.0 not working on Windows 10 1809

  1. Hi
    if the profile has been relocated into onedrive folder the path in the script will be broken.
    use :
    if (!(Test-Path -Path “$(Split-Path $profile)\Modules” -PathType Container)) { New-Item -ItemType “directory” “$(Split-Path $profile)\Modules” }
    to locate the Modules folder within the same folder as the $profile script
    and if you chose to do so you also need to change the DestinationPath for the Expand-Archive:
    DestinationPath = “$(Split-Path $profile)\Modules\PSReadLine”
    and the unblock to :
    dir “$(Split-Path $profile)\Modules\PSReadLine” | Unblock-File -Verbose

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.