PowerShell Predictive IntelliSense

Most of you will the “normal” usage of IntelliSense by hitting Strg+Space to get IntelliSense help for auto-completion of the command or parameter. As the world around PowerShell gets more complex from year to year, there is the need for some more assistance while typing your code. You can achieve this with PowerShell Predictive IntelliSense.

Predictive IntelliSense will assist you with your daily PowerShell use. It will help you to successfully type the commands you know (and don’t know). Predicted completion will appear as colored text while typing your command. This will help all PowerShell users to discover, edit and execute commands based on predictions from the PowerShell history – and domain specific plugins in PowerShell 7.

Predictive IntelliSense will assist you writing code based on your history and even with the help of artificial intelligence (AI) by searching in the documentation.

Demonstration of PowerShell Prediction
IntelliSense prediction example

Currently there are 2 options for prediction:

  1. History
    • available for PowerShell 5.1 and PowerShell 7
  2. History and Plugins
    • only available for PowerShell 7

Installation/Update of PSReadLine

Source: https://www.powershellgallery.com/packages/PSReadLine/

To get yourself started with using IntelliSense Predictions you first need to update the PSReadLine-Module.

Current release is 2.2.5. This command will install the latest available version:

Install-Module PSReadLine -Force

Enable / Disable Predictions

Right after installing PSReadLine, predictions are still disabled.

To enable predictions type the following command:

Set-PSReadLineOption -PredictionSource History

If you want to disable predictions type the following command:

Set-PSReadLineOption -PredictionSource None

Customize your experience

To match your favourite color scheme, you can customize the color of the prediction text.

By default the prediction is light-grey.

With the following commands you can customize it:

Set-PSReadLineOption -Colors @{ InlinePrediction = '#FF0000'}
PowerShell Prediction marked in Red
Prediction example color: red
Set-PSReadLineOption -Colors @{ InlinePrediction = '#9FC5E8'}
PowerShell Prediction marked in Light Blue
Prediction example color: light blue

To customize your PowerShell even further, there is an option to get a better overview of predicted commands: ListView

To enable ListView, type the following:

Set-PsReadLineOption -PredictionViewStyle ListView

Plugin prediction

With plugins you can also enable the prediction of code with the help of AI

PSReadLine Prediction in List Mode
Prediction plugins

When you’re working with Azure, there is a prediction plugin available, that helps you to get around approximately 4000 commands with an average of 10 parameters each.

To install the prediction plugin for Azure, type the following command:

Install-module -name Az.Tools.Predictor -RequiredVersion 1.0.1

Wait! There’s more!

Jason Helmick explains in his blogpost, even more features and possibilities:

  • Change foreground and background color of predicted text
  • Usage of keybindings
  • … and more. So check out his blog!

Leave a Reply

Your email address will not be published. Required fields are marked *