- Poll: How reliable are ChatGPT and Bing Chat? - Tue, May 23 2023
- Pip install Boto3 - Thu, Mar 24 2022
- Install Boto3 (AWS SDK for Python) in Visual Studio Code (VS Code) on Windows - Wed, Feb 23 2022
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.
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
Alternatively, you can run the following command on a PowerShell console:
Unblock-File $env:USERPROFILE\Downloads\PSReadLine.zip
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:
cp $env:USERPROFILE\Downloads\PSREadline\* $env:USERPROFILE\Documents\WindowsPowerShell\Modules\PSReadLine\
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:
Set-ExecutionPolicy RemoteSigned
Of course, Unrestricted and Bypass work, too.
To import the module, you need the following command:
Import-Module PSReadLine
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:
if ($host.Name -eq 'ConsoleHost') { Import-Module PSReadLine }
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:
(New-Object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | Invoke-Expression
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:
Install-Module PSReadLine
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:
Install-Module -Name PSReadLine
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.
Really… an article on how to install a powershell module…
you must be desperate
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?
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”
.
Zdzislaw, did you notice the link at the end of the article?
Excellent!
So many complaints about this article. As a PowerShell beginner, this is exactly what I was looking for, not only because I’m trying to install PSReadLine, but because I’ve never installed a third party module before.
Still helpful, even now 2018-Q1. Many thanks.
yo thanks alot. this is handy for new powershell users.