Share this article

Improve this guide

PowerShell history is not working? Check out these solutions

4 min. read

Updated onOctober 4, 2023

updated onOctober 4, 2023

Share this article

Improve this guide

Read our disclosure page to find out how can you help Windows Report sustain the editorial teamRead more

Windows PowerShellis incredibly easy to administrate once you learn the basics of the scripting language. Despite that, users might encounter a few hiccups here and there. Many of them have reported thatPowerShellis not accepting the Ctrl+Rshortcutto show the command history search.

Since this essentially means that users can no longer enjoy the history function, it’s definitely unpleasant.PowerShellhas a pretty great built-in command history to help you out with those complex lists that you have entered over time, but if you can’t use it, that’s a big problem.

If you are troubled by this issue too, to get around it we recommend the following.

What can I do when PowerShell history won’t work?

What can I do when PowerShell history won’t work?

1. Check the PSReadLine assembly

Many others have experienced the same problem after upgrading toWindows 10. You might not know that you’ve installed PSReadLine, but it comes bundled withWindows 10, so accept that it’s there.

Like it or not, it pretty much replaces the old-style command history features with more sophisticated functionality. The command history function inPowerShellis not built into the Windows Management Framework itself, but it’s based precisely on the third-party PSReadLine module.

To confirm it has any involvement this time, try to run Get-PSReadLineOption and note if you get thiserrorregarding the PSReadLine assembly:

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

If you see the above lines too, closePowerShell, then change keyboard layout toen-US. Open it back and check if PowerShell history works again.

2. Downgrade PSReadLine to 1.2

Upgrading PSReadLine to a new version could also cause thiserroryou’re getting. This mostly happens if you are runningPowerShellwith a non-en-US keyboard layout.

However, if the above steps made no difference, you could also try to downgrade PSReadLine to 1.2.

3. Try out alternative cmdlets to view the history

Suppose you typed and executed some complicated PowerShell commands and you want to take a peek now. You should be able to browse the entire history ofPowerShellcommands using the up / down arrows.

As always, you can also use several included cmdlets to work with your history. To view the history of commands you’ve typed, run the following cmdlet:Get-History

You may further search your history by piping the resulting output to the Select-String cmdlet. Don’t forget to replace “Search” in the cmdlet below with the actual text you want to search for:Get-History | Select-String -Pattern “Search”

In order to view more detailed information about previously executed commands, including the command status or start/end time, run this command instead:Get-History | Format-List -Property *

No less important, if things do work and you want to export commands from the current session to a file, use the Export-Clixml cmdlet:Get-History | Export-Clixml -Path c:pscommands_hist.xml

4. Increase number of remembered commands

Remember that the command line buffer keeps only the last 50 commands you typed. If wanting more is the actual problem you’re facing, just increase this number.

To make it happen, right-click the title bar of the PowerShell prompt window, selectProperties, then simply change the value ofBuffer SizeunderCommand History.

A potential cause of thiserroris thatPowershell‘s history is turned off. Here’s where you might have entered before:%userprofile%AppDataRoamingMicrosoftWindowsPowerShellPSReadlineConsoleHost_history.txt

You could have turned it off with:Set-PSReadlineOption –HistorySaveStyle SaveNothing

Does it ring any bells? The same goes if you’re looking for something after you fully clear the memory in the hope of a fresh start.

Just be careful: the Clear-History cmdlet can’t really be used to clear the history of commands. It simply clears the list of commands that the Get-History cmdlet displays.

Following the procedures mentioned in this article should help you to resolve the issue you were experiencing. If you’re aware of any other way to make PowerShell history work again, do tell us about it in the comments section below.

More about the topics:PowerShell

Radu Tyrsina

Radu Tyrsina has been a Windows fan ever since he got his first PC, a Pentium III (a monster at that time).

For most of the kids of his age, the Internet was an amazing way to play and communicate with others, but he was deeply impressed by the flow of information and how easily you can find anything on the web.

Prior to founding Windows Report, this particular curiosity about digital content enabled him to grow a number of sites that helped hundreds of millions reach faster the answer they’re looking for.

User forum

0 messages

Sort by:LatestOldestMost Votes

Comment*

Name*

Email*

Commenting as.Not you?

Save information for future comments

Comment

Δ

Radu Tyrsina