# Making the most out of the Azure CLI Interactive Mode

# The power of the Azure CLI

The Azure CLI (opens new window) is a very powerful tool. You can use it to do basically anything in Azure from the command prompt, including creating and deleting resources like Web Apps (opens new window) and VMs (opens new window). You can use the Azure CLI (opens new window) from your local computer or from the Azure Cloud Shell (opens new window).

In this post, we'll explore the interactive mode of the Azure CLI (opens new window). This is a special mode that enhances the behavior of the CLI.

# Prerequisites

If you want to follow along, you'll need the following:

# Using the Azure CLI Interactive Mode

Let's take a look at the Azure CLI interactive mode. We'll use the Azure Cloud Shell for this and you can also use an Azure CLI that you run on your local machine.

  1. Open Azure Cloud Shell, https://shell.azure.com/ (opens new window)
  2. Type az interactive to start the interactive mode

(Azure CLI interactive mode)

Autocomplete and examples

Azure CLI interactive mode helps you to be more productive. When you use it for a CLI command, like webapp show, it will automatically complete your command. It also shows you which parameters are available for the command and what the parameters mean (number 1 in the image). You also get a description of what the command does. For instance, for the webapp show command, it shows that this command will "Get the details of a web app" (number 2 in the image).
And on top of all of that, the interactive mode also shows examples of how you can use the command (number 3 in the image).

(Azure CLI interactive mode)

Scoping

When you use the interactive mode, you don't have to type az in front of your command. This is because this mode is already scoped to the az command. And you can scope to other commands as well. If you are working with Web Apps for instance, and don't want to type webapp for every command, you can scope to webapp by typing %%webapp. You can also scope deeper by scoping to the webapp create command with %%create. You can go back in scope by typing %%.. to go up one level or by typing %% to go back to the root scope.

(Scoping in the Azure CLI interactive mode)

Query

You can use the Azure CLI to query JSON results from commands that you run. For instance, when you create a Resource Group (opens new window), the result is a JSON string that contains the data for that Resource Group, including its id and name. In the Azure CLI interactive mode, you can use the JSON results of a previous command in other commands with JMESPath queries (opens new window). For instance, when you create a Web App, you can give it the name of a Resource Group that you've created in a previous command with "?? name":

(JMESPath query in the Azure CLI interactive mode)

External commands

You can run shell commands without leaving the Azure CLI interactive mode, like a bash command. You can run shell commands by typing #[cmd], for instance #mkdir to create a new directory.

(External commands in the Azure CLI interactive mode)

# Conclusion

You can be very productive in Azure with the Azure CLI (opens new window). And you can be even more productive when you use the Azure CLI interactive mode (opens new window). Go and check it out!

# Live streaming software development

On a side note - If you like Azure Tips and Tricks, then you might enjoy another project that I'm working on for live streaming. Check out my channel below and hit the follow button to know when I'm live.

Watch live video from mbcrump on www.twitch.tv