In a previous blog, I introduced you to the Azure Command Line Interface. This is a powerful tool for generating and controlling Azure resources.
This CLI has only one weak spot, the sheer limitless amount of features and settings. You have to remember a lot!
But with the introduction of the new Azure CLI shell, most of that pain is taken away.
Let’s check this out.
This is part three of a series of blogs regarding the Azure CLI:
- Getting started with Azure Command Line Interface 2.0
- Working with the IoT Hub using Azure Command Line Interface
- Azure CLI made easy. Using the shell
I assume you have already installed the Azure CLI. I can recommend updating to the latest version
pip install --user azure-cli --upgrade
After that, install the CLI shell using the same Python Package Index:
pip install --user azure-cli-shell
Once the command line is available again, start the CLI Shell:
This will open the shell:
First, make sure your dos-box is big enough to fill all features (especially the command buttons at the bottom). I just maximize the dos-box.
Next, you can see the current Azure subscription which is used, the last time you started the CLI. But wait, this does not mean the access is still granted. If you get a message the access is ‘revoked’ later on, just log in using:
note: you can leave away the ‘az’, you are already in the context of using the CLI. This shell is all about context!
If you wait with executing, you will see some examples appearing:
If not all examples are visible at once (here, the first out of two pages is shown), you can navigate to the next and previous using CTRL-Y and CTRL-N.
Command line commands
Although you are in the shell, it’s still possible to execute command line commands:
#dir *.* | more
or (my favorite):
This cleans up the screen.
The real power of this shell are the hints. Fill in this command:
iot hub create
Again the examples are shown:
If I time one more space, I get more information about the (requires) parameters:
So let’s try to create an IoT Hub in West Europe, What do I have to type as an identifier for this region? Let’s see:
This is really a time saver!
After an execution of a command, It should be possible to check the execution return code using ‘$’. I checked this out but in my case, next to the apparently correct return code, I also got a strange exception:
at the bottom of the shell, there are some command buttons:
Pressing F1 starts a simple dialog for hiding or showing layout features (do not forget to restart):
Use F2 for hiding and showing default values. It’s not exactly clear to me what these default values are and how to manipulate them. This does not seem to be the scoping, does it?
Use F3 for showing and hiding the summary of the shell commands, shown at the bottom of the screen.
You can narrow the scope using ‘%% [scope]’. Look at what happens when you type:
Note: In Windows, a space character must be typed, just after ‘%%’.
This will result in:
So you are working within a certain scope, in this case: ‘IOT’.
You can undo the scope using ‘%%’.
It’s easy to change the default subscription.
First check for available subscriptions:
<az> account list
This gives a list of all enabled subscriptions. add the “–all” parameter to see all subscriptions (eg. disabled ones).
Copy the GUID of your subscription you want to select.
<az> account set --subscription [GUID]
The Azure CLI Shell seems to be a valuable addition to the Azure CLI. Using this shell, you do not have to look up every command.
And check for the latest update of this shell using
pip install --user azure-cli-shell --upgrade