The PowerShell console in Windows 8 lacks a host of features that UNIX and Linux admins have enjoyed for decades. Jason Shirk’s PowerShell console extension PSReadLine is a free PowerShell module that adds numerous useful editor functions to Microsoft’s outdated CLI. In this post, you will learn how to install the module on Windows 8.1 and you’ll see how things have been improved significantly in Windows 10. In a follow-up post, I will show what you can do with PSReadLine.
Profile gravatar of Michael Pietroforte

Michael Pietroforte

Michael Pietroforte is the founder and editor of 4sysops. He is a Microsoft Most Valuable Professional (MVP) with more than 30 years of experience in IT management and system administration.
Profile gravatar of Michael Pietroforte

Just to make your mouth water a little, these are PSReadLine’s main features: syntax coloring, syntax error notification, improved line editing, multiline editing, command completion, command history search, and keyboard shortcuts.

Multi-line editing in PSReadLine

Multiline editing in PSReadLine

The installation instructions below might appear to be longwinded. However, the PowerShell beginner might fall into a few traps along the way. If you have imported third-party PowerShell modules before, you will know how to avoid these traps. You’ll also see that, thanks to the new package manager in PowerShell 5, things are getting a lot easier in Windows 10. However, you can also have comparable convenience with PowerShell 4 if you install a package manager on Windows 8.1, as you will see below.

Installing on Windows 8.1 with PowerShell 4 ^

First, you have to download PSReadLine.zip from GitHub.

Note: Don’t download PSReadLine-master.zip from the module’s main page. This file lacks the PSReadLine.dll file, and you will get this error message if you try to import the module:

Import-Module : The module to process 'PSReadLine.dll', listed in field 'NestedModules' of module manifest.

The next thing you should do is unblock the ZIP file. If you don’t unblock the file, you’ll get the following confusing error message when you try to import the module:

import-module : The specified module 'psdreadline' was not loaded because no valid module file was found in any module

To unblock the ZIP archive, right-click the file, select Properties, and then click Unblock.

Unblock PSReadLine.zip

Unblock PSReadLine.zip

Alternatively, you can run the following command on a PowerShell console:

I assumed here that you downloaded the file to the default download folder.

You can now unzip the file. If you don’t run PowerShell 5, I suggest that you do this with File Explorer because unzipping files in PowerShell 4 is quite cumbersome.

Because PSReadLine is a PowerShell module, you have to copy it to your PowerShell Modules folder in the Documents folder:

If you didn’t create the Modules folder before, this command will do it now.

Importing the PSReadLine module ^

To import the PSReadLine module, you have to launch a PowerShell console with administrator privileges and set your PowerShell execution policy to at least RemoteSigned:

Of course, Unrestricted and Bypass work, too.

To import the module, you need the following command:

If you don’t see any error message, PSReadLine should work now. To test it, you can run the Get-PSReadlineKeyHandler cmdlet to display the module’s key bindings.

If you like the module, you will want to import it automatically whenever you launch a PowerShell console. PowerShell’s module auto-loading won’t help you here because you usually won’t run one of the module’s cmdlets when you start working with the module. You should therefore import the module into your PowerShell profile.

I recommend adding the above import command to Microsoft.PowerShell_profile.ps1 in the WindowsPowerShell folder in your Documents directory (%USERPROFILE%\Documents\WindowsPowerShell) and not to profile.ps1. With the latter, you would also load the module when you start PowerShell ISE, which makes no sense because most of PSReadLine’s features won’t work there.

If you prefer to work with just one PowerShell profile, you can add these lines to profile.ps1:

The if clause ensures that the module will only be imported when you start the PowerShell console.

Installing with PsGet from GitHub ^

The installation procedure in Windows 8.1 is a bit longwinded if you download the module in a browser. Things get easier if we do it the Linux way and download the module directly from the online repository GitHub.

As with the first installation method described above, you should set your PowerShell execution policy to at least RemoteSigned.

To access the GitHub repository from a PowerShell console, we first need to download and install the PsGet module:

The New-Object cmdlet creates the .NET object Net.WebClient and the object’s DownloadString method downloads the PowerShell script GetPsGet.ps1. We can execute the script that installs PSGet by piping it to the Invoke-Expression cmdlet.

With the help of the PSGet module we now download PSReadLine from GitHub:

Installing PSReadLine from GitHub

Installing PSReadLine from GitHub

You can now import the module as described above.

Installing on Windows 10 with PowerShell 5 ^

In Windows 10, we don’t have to install the PsGet module because PowerShell 5 comes with PowerShellGet, a module that extends OneGet, the new package manager in PowerShell 5. Instead, from GitHub, you can install PSReadLine from the online repository PowerShell Gallery. As mentioned above, your PowerShell execution policy should be set to at least RemoteSigned.

You can simply download and install the PSReadLine module with this command:

Installing PSReadLine on Windows 10

Installing PSReadLine on Windows 10

If you didn’t install a package from a NuGet-based gallery before, you will be asked to install NuGet-anycpu.exe. After that, the PSReadLine module will be downloaded. I recommend that you read the text, which warns you that you are installing a module from an untrusted repository.

You are now ready to import the PSReadLine module.

In my next post, I will show you how PSReadLine improves your PowerShell console experience.

Take part in our competition and win $100!

Share
1+

Related Posts

4 Comments
  1. avatar
    Bob 2 years ago

    Really... an article on how to install a powershell module...
    you must be desperate

    0
  2. Profile gravatar of Michael Pietroforte
    Michael Pietroforte 2 years ago

    Bob, actually, I had the idea when I read a forum thread and saw how many had problems installing PSReadLine, most of them because they failed to unblock the module. Besides, what’s wrong with a blog posts for beginners? Have you been born with the knowledge that you can install modules from online repositories in PowerShell 5? And don’t you think that this “I am geekier than you” talk is a bit outdated and unprofessional?

    3+
  3. Profile gravatar of Zdzislaw Twardy
    Zdzislaw Twardy 2 years ago

    First Bobs comment is stupid, he probably had bad day, so please ignore him.
    But I have to admit that I am little disappointing that you Michael will not put more efforts to present all functions & possibilities which installing PSReadLine give you ads developer or user of PowerShell. people like not always have to much time to make deeper tests which possibilities have each tool, so in the end I use maybe only 20% - 30% of them. Please write more about PSReadLine. I am quite sure it will be appreciate by more people

    Regards "Stisse"
    .

    0
  4. Profile gravatar of Michael Pietroforte
    Michael Pietroforte 2 years ago

    Zdzislaw, did you notice the link at the end of the article?

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2017

Log in with your credentials

or    

Forgot your details?

Create Account