# Predictions and History, Fully Used

Set-PSReadLineOption makes the prediction list your standard view and lets PSReadLine remember 10000 commands instead of 4096, # and Tab bring back a command from this window by a word or its number, and Select-String finds every match in the saved history file at once.

Journeyman · PowerShell · Updated November 10, 2026

## After this lesson you can

- Show predictions as a list and keep a longer history with Set-PSReadLineOption
- Find an earlier command with # and Tab, or by searching the saved history file with Select-String

## Key takeaways

- Set-PSReadLineOption changes PSReadLine's settings for this window; -PredictionViewStyle ListView shows predictions as a list from the start.
- PSReadLine remembers 4096 commands; -MaximumHistoryCount 10000 makes that 10000. Put the line in your profile to keep it.
- Type # and part of a command, then press Tab: the newest command in this window with those letters comes back. #2 and Tab brings back command 2.
- Searching the saved history file with Select-String shows every matching command at once, even ones from months ago.

In August you zipped Grandma's birthday photos into the backup folder with one long `Compress-Archive` line. Now the picnic photos are edited and need the same, and that window closed weeks ago. You remember the idea, not the exact parameters. Your history remembers both. *Your Command History* showed the up arrow, Ctrl+R and the gray prediction; this lesson sets PSReadLine up to remember more and show it better, and adds two ways to search that aren't keys at all. An IT tech finds the command that fixed the same problem last month this way, and a developer finds last week's long deploy line.

The examples use the `photo-book` folder from *Keyboard Shortcuts at the Prompt*.

## Predictions as a list, every time

As you type, PSReadLine suggests a whole command from your history in gray, and **F2** switches to a list of suggestions under the prompt, each marked `[History]` when it came from your own commands. Microsoft calls these suggestions **Predictive IntelliSense**. If you like the list better, make it the view this window starts with:

```powershell
Set-PSReadLineOption -PredictionViewStyle ListView
Get-PSReadLineOption | Select-Object PredictionSource, PredictionViewStyle
```

```text
PredictionSource PredictionViewStyle
---------------- -------------------
HistoryAndPlugin            ListView
```

Read the name as *set* a *PSReadLine option*: it's the command for every PSReadLine setting, and `Get-PSReadLineOption` reads them back. `HistoryAndPlugin` means the suggestions come from your history and from plug-ins, extra modules that add suggestions of their own. In the list, the up and down arrows choose a line and Enter runs it. F2 still switches, and `InlineView` is the gray-text view.

## A longer memory

PSReadLine remembers your last 4096 commands for the up arrow, Ctrl+R and predictions. Someone who lives at the prompt passes that in a few months, and the oldest drop off. One setting makes it more:

```powershell
(Get-PSReadLineOption).MaximumHistoryCount
Set-PSReadLineOption -MaximumHistoryCount 10000
(Get-PSReadLineOption).MaximumHistoryCount
```

```text
4096
10000
```

`Set-PSReadLineOption` changes **this window only**: close it, and the next one starts at 4096 and the inline view again. That makes it safe to try a setting first. To keep one, put the same line in your profile (*Your Profile*).

## Search this window: # and Tab

The up arrow walks back one command at a time. A quicker way: type `#` and a few letters from the command, then press **Tab**. Open a new window and run these, so there's something to find:

```powershell
Set-Location ~\terminal-practice\photo-book
Get-ChildItem originals\2026\08-august\birthday -Name
Copy-Item originals\2026\07-july\picnic\IMG_0714.jpg edited\2026\07-july\picnic\IMG_0714-edit.jpg
Get-ChildItem edited\2026\08-august\birthday -Name
Get-History
```

```text
IMG_0815.jpg
IMG_0816.jpg
IMG_0817.jpg
IMG_0815-edit.jpg
IMG_0817-edit.jpg

  Id     Duration CommandLine
  --     -------- -----------
   1        0.035 Set-Location ~\terminal-practice\photo-book
   2        0.019 Get-ChildItem originals\2026\08-august\birthday -Name
   3        0.017 Copy-Item originals\2026\07-july\picnic\IMG_0714.jpg edited\2026\07-july\picnic\IMG_0714-edit.jpg
   4        0.013 Get-ChildItem edited\2026\08-august\birthday -Name
```

Your durations will differ. Now type `#picnic` and press Tab. The line becomes the newest command with `picnic` in it, ready to change before you press Enter:

```text
Copy-Item originals\2026\07-july\picnic\IMG_0714.jpg edited\2026\07-july\picnic\IMG_0714-edit.jpg
```

`#birthday` and Tab brings back command 4, the newest with `birthday`; press Tab again for the older one, command 2. Capital letters don't matter. A number works too: `#2` and Tab puts command 2, from `Get-History`'s Id column, on the line. Unlike `Invoke-History`, nothing runs until you press Enter. (On its own, `#` starts a *comment*, a note PowerShell ignores; it's the Tab that makes it a search.)

`#` and Tab searches only this window's history, the list `Get-History` shows. Ctrl+R also reaches the commands from earlier windows.

## Search everything: the saved history file

Ctrl+R shows one match at a time. To see every match at once, search the file PSReadLine saves your history in, with `Select-String` (*Finding Text: Select-String*). `(Get-PSReadLineOption).HistorySavePath` is that file's path:

```powershell
Get-Content (Get-PSReadLineOption).HistorySavePath | Select-String 'Compress'
```

```text
Compress-Archive -Path edited\2026\08-august\birthday -DestinationPath backup\birthday-edits.zip
```

That's Sam's August line; yours lists your own commands, or nothing if you haven't zipped anything yet. When the line is in your own history, Ctrl+R and `Compress` bring it to the prompt, and the keys from *Keyboard Shortcuts at the Prompt* change `08-august\birthday` to `07-july\picnic` and `birthday-edits` to `picnic-edits`. The picnic version:

```powershell
Compress-Archive -Path edited\2026\07-july\picnic -DestinationPath backup\picnic-edits.zip
Get-ChildItem backup -Name
```

```text
picnic-edits.zip
```

Every word of a line is searchable this way: `Select-String 'birthday'` lists every command you ever ran on those photos.

**Windows PowerShell 5.1** has no predictions, so no `-PredictionViewStyle` and no F2 list, but `-MaximumHistoryCount`, `#` with Tab, and the saved file work there too. **On a Mac or Linux** everything in this lesson works the same.

**Try it.** Make the list view this window's style and type `Get-Ch` to pick a command from the list. Then count the `Copy-Item` lines in your saved history: put the `Select-String` line in parentheses and add `.Count`.

## Check yourself

2 questions to try on the lesson page.

## So what

Your history is a searchable record of everything that worked. A longer memory, the list view, `#` and Tab, and a search of the saved file mean you work something out once and never again.

## Key terms

- [PSReadLine](https://www.ask-codey.com/glossary/psreadline)
- [Get-History](https://www.ask-codey.com/glossary/get-history)
- [Predictive IntelliSense](https://www.ask-codey.com/glossary/predictive-intellisense)
- [Set-PSReadLineOption](https://www.ask-codey.com/glossary/set-psreadlineoption)

## Cheat sheets

- [Predictions and History, Fully Used](https://www.ask-codey.com/cheat-sheets/powershell-predictions-cheat-sheet)

## Related

- [Your Command History](https://www.ask-codey.com/lessons/powershell-command-history)
- [Keyboard Shortcuts at the Prompt](https://www.ask-codey.com/lessons/powershell-keyboard-shortcuts)
- [Finding Text: Select-String](https://www.ask-codey.com/lessons/powershell-select-string)
- [Your Profile](https://www.ask-codey.com/lessons/powershell-profile)

Source: https://www.ask-codey.com/lessons/powershell-predictions
