It can be extremely useful to use the Azure CLI to manage / manipulate your Azure resources from the command-line. However, many of the commands will output a large amount of JSON that can be extremely difficult to read at the command-line. When using the Azure CLI within the Bash shell, you can use a couple techniques to make the JSON output much more readable, and using these techniques will really increase your productivity at the command-line.
Azure CLI 2. 0 Command Output Options
When running many of the Azure CLI 2. 0 commands it will output JSON to the command-line. This can be difficult to read at the command-line, especially when you need to scroll a lot in order to sift through the huge output. To solve this the Azure CLI 2.0 supports the use of the “–output” or “-o” parameters to be appended to commands that allows you to easily modify the format of the commands output.
Here’s the “-o” / “–output” options supported:
- table – outputs in an easily readable table format
- json – outputs in JSON format
- jsonc – outputs in JSON format with a little color highlighting
- tsv – outputs in a tab delimited format
It’s really nice to have output format options, but the “table” option is likely the best to output an easily readable result, and the “jsonc” is probably the second best since it outputs JSON that’s a little easier to read.
Here’s a few example Azure CLI 2.0 commands using the Output parameter:
az resource list -o table az resource list --output table
az web app show -g myblogsite -n myblogsite -o table
az vm list -o table
Filter Results using GREP
On Linux you can use “grep” to filter the results of the Azure CLI 2.0 command output. You can do this to easily sort out specific data in the result to easily find what you’re looking for.
Here’s an example of using “grep” by piping (via “|”) the results of the Azure CLI 2.0 command to “grep“:
az resource list -o table | grep "asia"
Here’s another example:
az resource list -o table | grep "blog"
If you’re using Linux or macOS, then the above techniques should work for you just fine. If you’re using Windows 10, you can install and use the Ubuntu Bash for Windows 10 to get access to the above techniques as well.
How do you loop in Azure CLI, i need to reboot list of node in azure batch.
This link in the documentation should help guide you in the right direction: https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-linux-cli-sample-restart-by-tag