Interacting with the Azure CLI v2.0

Navneet Thillaisthanam
4 min readJun 18, 2017

Azure, from the time I can remember, has been offering a XplatCLI (reads Cross Platform CLI) for managing resources on Azure. However, I always favoured the Azure PowerShell as the ease of use with PowerShell was so much more than XplatCLI.

Following screenshots are the outputs of the Azure PowerShell and XplatCLI respectively and it is rather evident why I favoured the PS utilities more than the CLI.

Output of the PowerShell Cmdlets for Azure
Output of the Azure CLI (XplatCLI)

I always found the commands in PS much more intuitive than the CLI versions. However, this was the lesser evil compared to the other peeve of using the CLI. You had to hit Enter after typing each section of the command which while cumbersome was also a terrible blot on productivity. Not to mention the resulting output was festered with unnecessary text and made sighting information you need pretty much a needle in a haystack story. Had to script something using the XplatCLI? May the Gods have mercy on you…

Proving that Microsoft in the recent years is indeed obsessed about customers, the v2.0 of the Azure CLI come with a much-needed re-architecting of the command outputs. A detailed and wonderfully insightful article is covered by Chris Pietschmann here. In a nutshell, multiple output formats are now supported — json, jsonc, tsv and table. I urge you to read Chris’s article as it really sells you on using the 2.0 CLI. I will wait! Go on…

Now that you have a reasonable fair amount of familiarity of the CLI 2.0. Let us revisit the second problem at hand — the non-intuitive commands needing you to hit Enter a few tens of times before you figure out the best command fulfilling your need. The Azure CLI 2.0 introduces a new feature that really kills all the opposition that I had against the CLI and is documented in the Azure CLI Documentation that the new Azure Cloud Shell very helpfully offers while in a session. I must, however, admit that I have only used the 2.0 in Azure Cloud Shell and not on any of the other machines that I use. But I digress… back to the issue at hand — Save the Enter key.

The Azure CLI Interactive session drops the user into an interactive shell scoped to the Azure commands context. Think of it like the Python interactive shell that most of us are familiar for eons now.

Invoking the interactive shell is rather easy — just type the following command in the shell and see the magic unfold.

user@Azure:~$az interactive

The icing on the cake is the colour schemes that can be chosen depending on your mood for the day. :)

Azure Interactive Shell

Now you can enter any of the commands for managing the resources in Azure. The CLI has been enabled with Intellisense-like feature to offer you the commands in the context of the command being typed enabling you to sift through the multitude options to select the right one. All this without once needing you to hit the Enter key ever!!!

Intellisense on Azure Interactive Shell

Hit the Tab key twice at the beginning of the command to get a list of all the service scopes.

Much like how most lesser mortals (I definitely bring the last of that list too) program using Python, I can now use this interactive shell for getting my automation scripts as well as managing my Azure environment.

I really wish cloud shell is offered as a standalone webapp too (as opposed to being a feature in Azure portal). Fret not — there is a user voice feedback asking for the same and I am darn sure Microsoft is listening…

Happy hacking!!

--

--