Azure Command Line 2.0 generally available

Azure Command Line 2.0 generally available.

This new version of Azure CLI should feel much more native to developers who are familiar with command line experiences in the bash enviornment for Linux and macOS. With simple commands that have smart defaults for most common operations and that support tab completion.

The number of Azure services supported in Azure CLI 2.0 has grown and now it have command modules for sql, documentdb, redis, and other.

Installing the Azure CLI

The CLI runs on Mac, Linux, and of course, Windows. Get started now by installing the CLI on whatever platform you use.

Here’s an example of the features included with the “vm command”:

Working with the Azure CLI

Accessing Azure and starting one or more VMs is easy. Here are two lines of code that will create a resource group and a Linux VM using Azure’s latest Ubuntu VM Image in the westus2 region of Azure.

az group create -n MyResourceGroup -l westus2
az vm create -g MyResourceGroup -n MyLinuxVM --image ubuntults

Using the public IP address for the VM, connect directly to your VM from the command line:

ssh <public ip address>

For Windows VMs on Azure, you can connect using remote desktop (“mstsc <public ip address>” from Windows desktops).

The “create vm” command is a long running operation, and it may take some time for the VM to be created, deployed, and be available for use on Azure.

az vm create -n MyLinuxVM2 -g MyResourceGroup --image UbuntuLTS --no-wait

The Azure CLI 2.0 lets you list your Azure resources and provides different output formats.

--output        Description
json    json string. json is the default. Best for integrating with query tools etc
jsonc   colorized json string.
table   table with column headings. Only shows a curated list of common properties for the selected resource type in human readable form.
tsv     tab-separated values with no headers. optimized for piping to other tex-processing commands and tools like grep, awk, etc.

You can use the “–query” option with the list command to find specific resources, and to customize the properties that you want to see in the output. Here are a few examples:

# list all VMs in a given Resource Group
az vm list -g MyResourceGroup --output table

# list all VMs in a Resource Group whose name contains the string ‘My’
az vm list --query “[?contains(resourceGroup,’My’)]” --output tsv

# same as above but only show the 'VM name' and 'osType' properties, instead of all default properties for selected VMs
az vm list --query “[?contains(resourceGroup,’My’)].{name:name, osType:storageProfile.osDisk.osType}” --output table

Azure CLI 2.0 supports management operations against SQL Server on Azure.

# Create a new SQL Server on Azure
az sql server create -n MySqlServer -g MyResourceGroup --administrator-login <admin login> --administrator-login-password <admin password> -l westus2

# Create a new SQL Server database
az sql db create -n MySqlDB -g MyResourceGroup --server-name MySqlServer -l westus2

# list available SQL databases on Server within a Resource Group
az sql db list -g MyResourceGroup --server-name MySqlServer


You might also like

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More