Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 57 ยท Cloud and Azure Basics

Portal, Azure CLI and PowerShell

Learn the three ways to manage Azure: the portal, the az CLI and Azure PowerShell. Cover az command structure, JMESPath --query, output formats, Cloud Shell and REST.

You can manage Azure in three main ways: the Azure portal (a website), the Azure CLI (az commands) and Azure PowerShell (cmdlets such as Get-AzVM). There are also SDKs for programming languages and templates for infrastructure as code. They look very different, but they all end up doing the same thing: sending requests to one REST API.

Knowing this makes the tools less mysterious and tells you which one to use when. This lesson explains each tool, how az commands are structured, and how to shape output with the --query option. All commands are shown read-only because they need a real subscription. The runnable example is a Node.js stand-in that takes az-style JSON and applies a small JMESPath-like query, so you can practice the query language without Azure.

Three tools, one API

  • The portal is best for exploring, learning and one-off visual tasks. You can see relationships between resources and read the documentation links next to each setting. It is poor for repeating work, because clicks cannot be reviewed, versioned or automated.
  • Azure CLI is a cross-platform command-line tool (Windows, macOS, Linux). Commands are short, output is JSON by default, and it fits shell scripts and pipelines well.
  • Azure PowerShell is a PowerShell module (Az). Commands follow the PowerShell Verb-Noun style and return objects, which suits people who already use PowerShell pipelines.

Everything a tool does goes through Azure Resource Manager, the front door of the platform (explained in Resource Groups and Azure Resource Manager). That is why a resource created in the portal shows up immediately in the CLI, and why all three tools respect the same permissions.

flowchart LR
    P["Portal"] --> ARM["Azure Resource Manager<br/>REST API"]
    C["az CLI"] --> ARM
    S["PowerShell"] --> ARM
    K["SDKs and Bicep"] --> ARM
    ARM --> R["Resources"]

Every management tool sends requests to the same REST API.

Azure Cloud Shell

Cloud Shell is a browser-based terminal inside the portal. It comes with az, PowerShell, git, kubectl, Terraform and an editor already installed, and you are already signed in. A small file share is mounted so your files survive between sessions. It is a quick way to try commands without installing anything. For daily work most people install the CLI locally.

Installing and signing in

After installing the CLI, the first command is to sign in, then check which subscription you are using:

Terminal
az login
az account show --output table
az version

az login opens a browser for interactive sign-in. In scripts and pipelines you do not sign in with a person's password; you use a service principal or a managed identity (see Managed Identities and Service Principals). The PowerShell equivalent is Connect-AzAccount.

The structure of an az command

Every az command follows the same shape: az <group> [<subgroup>] <command> [arguments].

Terminal
az group create --name rg-demo --location westeurope
az group list --output table
az vm list --resource-group rg-demo
az storage account show --name stdemo001 --resource-group rg-demo
az group delete --name rg-demo --yes --no-wait

The pattern is group, then an action word, usually create, list, show, update or delete. Arguments are named with double dashes. Handy global options:

  • --help (or -h) shows documentation at any level, for example az vm --help.
  • --output (or -o) chooses the output format.
  • --subscription runs one command against a specific subscription without changing your default.
  • --no-wait returns right away instead of waiting for a long operation.
  • --verbose and --debug show what the CLI is doing, including the REST calls.

Some commands can be repeated safely and some cannot, so read the output before repeating one. Declarative deployments with Bicep (see Bicep and ARM Templates) are the reliable way to get repeatable results.

Output formats

The CLI can print the same data in several formats:

Format Flag Best for
JSON -o json (default) Scripts and full detail
Colored JSON -o jsonc Reading JSON in a terminal
Table -o table Quick human reading
TSV -o tsv Feeding values into shell variables
YAML -o yaml Readable, config-like output
None -o none Commands where you ignore the output

tsv is the one to remember for scripts, because it prints raw values without quotes:

Terminal
SUB_ID=$(az account show --query id --output tsv)
echo "Using subscription $SUB_ID"

Shaping output with --query

The CLI's --query option uses JMESPath, a query language for JSON. It runs on the client after the response arrives. You can pick fields, filter lists and rename columns. Assume this is the JSON returned by az vm list:

JSON
[
  { "name": "web-1", "location": "westeurope", "size": "Standard_B2s", "state": "running" },
  { "name": "web-2", "location": "westeurope", "size": "Standard_B2s", "state": "stopped" },
  { "name": "db-1",  "location": "eastus",     "size": "Standard_D4s_v5", "state": "running" }
]

Common queries on it:

Terminal
az vm list --query "[].name"                              # every name
az vm list --query "[0].name"                             # first item
az vm list --query "[?location=='eastus'].name"           # filter with [?...]
az vm list --query "[].{Name:name, Size:size}" -o table   # rename columns

In JMESPath, [] flattens a list and projects the rest of the expression over every element, [?condition] filters, and {Key:path} builds a new object. String literals in a filter use single quotes, which is why you wrap the whole query in double quotes in Bash.

A query engine stand-in

The following Node.js program is not the real JMESPath library; it is a tiny stand-in that supports exactly the four forms above, so you can see how such a projection works. It runs on the site's Node runner.

Node.js A tiny JMESPath-like query

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The real JMESPath supports far more: functions such as length(), sort_by(), pipes (|), multi-select lists and nested filters. If you want the full language, practise with real --query expressions once you have an account.

Azure PowerShell for comparison

The same tasks in PowerShell return objects instead of JSON text, which you filter with the normal PowerShell pipeline:

POWERSHELL
Connect-AzAccount
Get-AzResourceGroup | Select-Object ResourceGroupName, Location
Get-AzVM | Where-Object { $_.Location -eq 'eastus' } | Select-Object Name

The CLI is usually the first pick in documentation and in Linux or macOS pipelines; PowerShell is popular in Windows-centred teams. Both are equally capable, so pick one and stay consistent within a project.

The REST API underneath

You can call the API directly. az rest sends an authenticated request to any ARM endpoint, which helps when a feature is too new for the CLI:

Terminal
az rest --method get \
  --url "https://management.azure.com/subscriptions/<subscription-id>/resourcegroups?api-version=2021-04-01"

Every REST call names an API version, a date string, so services can change without breaking existing callers. You will see these api-version values in ARM templates and Bicep files as well.

A simulated resource list

To practise filtering the way you would script it, the second example works on resource-style records with tags. It uses plain JavaScript, in the browser console editor.

JS Filter resources like a script

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Portal productivity: dashboards, search and Cloud Shell

A few portal habits save hours. They matter more than any single click path, because the portal changes its layout from time to time.

Dashboards

A portal dashboard is a canvas of tiles: resource health, a metric chart, a Log Analytics or Resource Graph query result, a markdown note, a list of pinned resources. Pin a chart from any resource (the pin icon on the chart), then arrange tiles on the dashboard. Dashboards are themselves Azure resources, so they live in a resource group, can be private or shared with RBAC, and can be exported as JSON and deployed from a template. You can set a time range and an auto-refresh interval on a dashboard so a wall display stays current. For rich, long-lived monitoring views, Azure Monitor workbooks, Azure Managed Grafana or Power BI are stronger; a dashboard is best as a quick personal or team start page.

Finding things quickly

  • The global search bar at the top finds resources, services, docs and even settings; the keyboard shortcut G then / focuses it.
  • Favorites and the portal menu let you pin the five services you use daily; hide the rest.
  • Recent and All resources with filters (subscription, type, tag, location) replace endless scrolling; save a filtered view as a favorite.
  • The Quickstart Center (search for it) offers guided checklists for common starting tasks, and each blade's Diagnose and solve problems page offers troubleshooting steps for that resource.
  • Appearance settings let you choose a dark theme, language and regional format, and the portal remembers them.

Cloud Shell in more detail

The first time you open Cloud Shell it asks to create a small storage account and an Azure Files share (a few GB), mounted as clouddrive; your home directory image is saved there, which is why your scripts survive a session. You can choose an ephemeral session with no storage if you only run quick commands. The shell times out after about 20 minutes of inactivity, runs on a free container host and has az, PowerShell, kubectl, terraform and editors preinstalled. It integrates with Visual Studio Code through the Azure extension, and with the mobile app, which can also start and stop VMs, check alerts and run Cloud Shell commands when you are away from a laptop.

Terminal
ls ~/clouddrive
code deploy.bicep      # opens the built-in editor

A dashboard as data: a stand-in

Since a dashboard is just JSON describing tiles, a small script can build one. The stand-in generates the tile list for a team dashboard and prints the layout.

JS Describe a dashboard as tiles

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What do the Azure portal, Azure CLI and Azure PowerShell have in common?

    All management tools talk to Azure Resource Manager, so results and permissions are the same regardless of the tool.
  2. 2. Which output format is best for putting a raw value into a shell variable?

    TSV prints raw values without quotes, so it is the usual choice for capturing a value in a script.
  3. 3. What does --query "[?location=='eastus'].name" do?

    --query uses JMESPath and runs on the client after the response arrives. [?...] filters items and .name projects the field.
  4. 4. Which command shows the active subscription?

    az account show prints the current subscription and tenant. Checking it before deploying prevents mistakes.

Summary

  • The portal, az CLI, PowerShell, SDKs and templates all call the same Resource Manager REST API.
  • az commands follow az <group> <command> --options; --help, --output, --query and --subscription are the options you use most.
  • --query uses JMESPath on the client; -o tsv gives raw values for scripts.
  • Cloud Shell gives a ready terminal in the browser; az rest calls the API directly.
  • Use scripts and templates, not clicking, for anything you must repeat.

Next: Resource Groups and Azure Resource Manager.