[Solved] PSReadLine not working in PowerShell 6

Context

You are now eager to test PowerShell 6, but in the current version (6.2) PSReadLine and your usual shortcuts are not working at all.

When you try to have a look at the PSReadLine configuration you get the following errors:

Get-PSReadLineKeyHandler : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
At line:1 char:1
+ Get-PSReadLineKeyHandler
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-PSReadLineKeyHandler], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetKeyHandlerCommand
Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
At line:1 char:1
+ Get-PSReadLineOption
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-PSReadLineOption], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetPSReadLineOption

Workaround

There is a GitHub issue here but it has been closed.
However, according to Steve LEE:

There isn’t a new beta coming soon, but you can pick up the nightly build which has the fix.

So what you can do is to:

  1. Rename the C:\Program Files\PowerShell\6\Modules\PSReadLine folder.
    Rename-Item -Path 'C:\Program Files\PowerShell\6\Modules\PSReadLine' -NewName PSReadLine.old
    
  2. Download the PSReadLine.zip file from here.
    Invoke-WebRequest -Uri 'https://ci.appveyor.com/api/buildjobs/3ejmf131eakd0th7/artifacts/bin%2FRelease%2FPSReadLine.zip' -OutFile C:\Temp\PSReadline.zip
    
  3. Unzip the file to the C:\Program Files\PowerShell\6\Modules\PSReadLine folder.
  4. Expand-Archive -Path C:\temp\PSReadline.zip -DestinationPath 'C:\Program Files\PowerShell\6\Modules'
    
  5. Restart your PowerShell 6 console

More about

PSReadLine (Microsoft Docs)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s