DEV Community

loading...

Getting started with the AZ Predictor PowerShell module for Azure

omiossec profile image Olivier Miossec ・3 min read

When using the Azure module in interactive mode, you can feel the frustration. There are more than 4000 cmdlets in the Azure Module, and it continues growing. Each of these cmdlets has a series of parameters and parameters set, you have to remember in order to make them work. You cannot expect someone to know them perfectly. It can be a complex world, even for the most experienced peoples.
For example, there are, at this time, 184 cmdlets for the Azure Application Gateway resource.

You can make the test.

Get-Command -name *applicationgateway* | measure-object | select-object count
Enter fullscreen mode Exit fullscreen mode

To work with the Application Gateway, you will need to navigate between your shell windows and Microsoft Doc and your shell.

PowerShell gives you a command completion by type the first letters of a cmdlet and the TAB touch.

Alt Text

But it doesn't solve all our puzzles on how to type a cmdlet with the needed parameters?

The new AZ Predictor is here to solve this problem. This module is a tool to help users to navigate on cmdlet syntaxes. It can help black belt PowerShell users as well as beginners to have a better command line practice with the Azure module.

This module is available on all platforms supported by PowerShell 7.1, Windows, various Linux platforms, and MacOS 10.13 and up. It uses the predictive IntelliSense feature from the PSReadline module version 2.2 beta 1. To provide suggestions to the IntelliSense feature, the new AZ Predictor module makes API calls, so Internet access is needed.

To install the module, you need to update your PowerShell 7 version to 7.1 and install the version 2.2.0 Beta1.

Install-Module PSReadline -AllowPrerelease 
Enter fullscreen mode Exit fullscreen mode

Then you can install the Az Predictor module.

Install-Module -Name Az.Tools.Predictor
Enter fullscreen mode Exit fullscreen mode

After this, you will need to stop your PowerShell session by closing the terminal windows used to install the two modules.

After opening a new PowerShell session, you can use the predictor module.

First import the module

import-module Az.Tools.Predictor
Enter fullscreen mode Exit fullscreen mode

Then enable the prediction option in the PsReadline module

Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Enter fullscreen mode Exit fullscreen mode


`
After that, you will need to choose how to see your predictions. There are two options, InlineView and ListView

The InlineView option presents the plausible completion of a command you type in a terminal session.
For get-AzApplicationGateway

Alt Text

The ListView, will give you a list of suggestion based on what you typed, it includes elements from your history, things you typed in the past, and predictions from API.

For the same cmdlet

Alt Text

You can select any of the suggestions

Alt Text

To change the option

powershell
Set-PSReadLineOption -PredictionViewStyle InlineView|ListView

For a long PowerShell session, you will find the InlineView less intrusive, as it will not present a long list of options each time you type a command in your terminal.
But in an expletory mode, the ListView option can help to solve problems you may have with a cmdlet you don't know well.

Discussion (0)

pic
Editor guide