how to Use a Select Statement With Azure CLI

This blog post will show you how to use a select statement with Azure CLI and get the same result as you were using PowerShell.

If you come from a PowerShell background, you are probably very familiar with the select statement, which allows us to select specific items from an output.

Azure CLI

In Azure CLI, there is no select option; however, we can use the –query switch and modify the output.

Let’s start with a basic example of getting all the Public IP address in a subscription. If you run the following command without using the –query option, you will data that you might don’t like.

  az network public-ip list --output table 

To filter the result, we can use the following line to give the name, location and IP address without extra information.

 az network public-ip list --query '[].{Name:name, Location:location, IP:ipAddress}' --output table

If you would like to find out which information is available, run the following command with a JSON output and note the field you would like to display.

  az network public-ip list --output json

To display a single value use the following command.

az network public-ip list --query [].name --output table

Note: Names in Azure CLI are case sensative.

Processing…
Success! You're on the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.