PowerShell Predictive IntelliSense

Written by 7:15 am PowerShell

PowerShell Predictive IntelliSense

2020 must have been a busy year because I missed one of the greatest new PowerShell features called Predictive IntelliSense. Back in November 2020, Jason Helmick announced PowerShell PSReadLine 2.1 with Predictive IntelliSense.

Update: PSReadLine version 2.2 is now general available.

One of the first things you learn when using a shell usually is tab completion. Tab provides automatic help when you are typing a command. However, we all know that the world around us gets increasingly complex. For example, the Azure PowerShell module offers over 4000 cmdlets with on average 10 parameters each. While tab-completion often is very helpful, wouldn’t it be great if the shell predicts what I am trying to do, based on my history or even with artificial intelligence (AI) pulled from the documentation? PowerShell Predictive IntelliSense is here to help with exactly that.

PowerShell Predictive IntelliSense
PowerShell Predictive IntelliSense

PowerShell Predictive IntelliSense uses my local command history and suggests the command I want to use. And with the latest version of PSReadLine 2.2.2 it can have additional plugins. These additional providers enhance predictions by providing domain-specific command and task completions, for example, for Azure PowerShell commands.

Keyboard shortcuts

Key bindings control cursor movement and additional features within the prediction. To support ListView, additional key bindings have been added to the Windows edit mode.

F2 is bound with SwitchPredictionView by default for switching between the InlineView and ListView.

Ctrl+z will revert to the original line when a list item is selected and keep the list view.

Escape will revert to the original line, whether a list item is selected, and clear the list view.

UpArrow and DownArrow are used to select an item in the ListView. To navigate history commands while the ListView is present, first press Escape to clear the ListView, then use UpArrow and DownArrow.

With Alt+A you can jump from parameter input to parameter input.

Get started with PowerShell Predictive IntelliSense

Predictive IntelliSense is implemented in the PowerShell engine and presented through the PSReadLine module. You can use the current version, which comes with PowerShell 7.2, or you can use some additional features with the latest beta release.

PSReadLine 2.2.2 + History Based Prediction

PowerShell Predictive IntelliSense InlineView
PowerShell Predictive IntelliSense InlineView

History-based predictions is available in the following versions:

Availability:

  • PSReadLine 2.2.2 currently available for download from PSGallery

Supported PowerShell versions:

Install PSReadLine 2.2.2:

Install-Module PSReadLine -Force

By default Predictive IntelliSense is disabled, you can enable it by running the following commands:

Set-PSReadLineOption -PredictionSource History

PSReadLine Plugin Prediction

PowerShell Predictive IntelliSense ListView
PowerShell Predictive IntelliSense ListView with History and Plugin

Version 2.2.2 brings ListView and a prediction plugin.

Availability:

  • PSReadLine 2.2.2 currently available for download from PSGallery

Supported PowerShell versions for ListView (History-based predictions only):

Supported PowerShell versions for the plugin subsystem (History and plugin predictions):

  • PowerShell 7.2
Install-Module PSReadLine -Force

By default, Predictive IntelliSense is disabled, you can enable it by running the following commands:

Set-PSReadLineOption -PredictionSource HistoryAndPlugin
#OPTIONAL you can also enable ListView
Set-PSReadLineOption -PredictionViewStyle ListView

One of the currently available plugins is Az Predictor, which helps you predict Azure PowerShell cmdlets. I will show you more about Az Predictor next week.

But wait there is more!

In his blog post, Jason Helmick shows even more functionality like:

  • Change the Color for Predictions using.
    Set-PSReadLineOption -Colors @{ InlinePrediction = ‘#8A0303’}
    Set-PSReadLineOption -Colors @{ InlinePrediction = ‘#2F7004’}
    Set-PSReadLineOption -Colors @{ InlinePrediction = “$([char]0x1b)[36;7;238m”}
  • Key Bindings for Predictions (List of additional suggested key bindings defined in PSReadLine SamplePSReadLineProfile.ps1)
  • and much, much more! So make sure you check out his blog post!

PowerShell Predictive IntelliSense Conclusion

I think the PowerShell Predictive IntelliSense feature is one of the best things since sliced bread. It can make you much more productive using PowerShell in so many different ways. And with the additional AI-powered modules, for example, Az Predictor, which kind of reminds me of the Azure CLI “az find” command, will help deal with more complex scenarios.

If you have any questions or comments, feel free to leave a comment below.

Tags: , , , , , , , , , , Last modified: November 18, 2022
Close Search Window
Close