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.

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 beta of PSReadLine 2.2.0-beta1 it can have additional plugins. These additional providers enhance predictions by providing domain-specific command and task completions, for example, for Azure PowerShell commands.

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.1, or you can use some additional features with the latest beta release.

PSReadLine 2.1.0 + History Based Prediction

PowerShell Predictive IntelliSense InlineView
PowerShell Predictive IntelliSense InlineView

History-based predictions is available in the following versions:

Availability:

  • PSReadLine 2.1.0 currently available for download from PSGallery
  • PSReadLine 2.1.0 will ship with PowerShell 7.1

Supported PowerShell versions:

Install PSReadLine 2.1.0:

Install-Module PSReadLine -RequiredVersion 2.1.0

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

Set-PSReadLineOption -PredictionSource History

PSReadLine 2.2.0-beta1 + Plugin Prediction

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

Version 2.2.0-beta1 brings ListView and a prediction plugin.

Availability:

  • PSReadLine 2.2.0-beta1 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.1+
Install-Module PSReadline -AllowPrerelease 

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’}
  • 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: February 25, 2021
Close