Azure CLI example

Introduction

This is a note of things that are often used in the Azure CLI. There is also the operation of Azure resources by CLI, so install the CLI for each OS.

Command example

For example, running it in PowerShell launches a browser, from which you log in with your Azure account.

The following is an example of execution in PowerShell. (However, each ID has been changed to an appropriate value.) The value of homeTenantId corresponds to the tenant ID of the specified directory.

PS C:\Users\user> az login
You have logged in. Now let us find all the subscriptions to which you have access...
The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
b5c0fe9f-a254-4728-a740-dc1d25d92c18
267f1a06-a596-43fc-828a-67547938399f
[
{
"cloudName": "AzureCloud",
"homeTenantId": "d4278972-2b8a-4be6-9011-846db11ae6c6",
"id": "5539a220-9e9a-402a-a75b-1edef17e99ef",
"isDefault": true,
"managedByTenants": [],
"name": "subsc1",
"state": "Enabled",
"tenantId": "f321d4ad-6443-4991-9775-fa558b1a384b",
"user": {
"name": "user@example.com",
"type": "user"
}
}
]
PS C:\Users\user>

Subscription

View subscription list

az account list --output table
az account list -o table

Resource group

View a list of resource groups in your subscription

az group list --output table

Create a resource group in your subscriptionCreate a resource group in your subscription.

az group create  --name <resource-group-name> --location <resource-group-location>

Resource

Display resource list in resource group (specify resource type as an option)

az resource list --name <resource-group-name> --resource-type Microsoft.Web/sites

Extract only the name column from the resource list

az resource list --query "[].{name:name}" -o table --resource-type Microsoft.web/sites

Storage account

Storage account list

az storage account list -o table

Network

Output Azure DNS zone list in JSON format

az network dns zone list -o json

Virtual Machine

Create Ubuntu 18.04 with admin account azureuser

az vm create \
--resource-group Resource group name \
--name virtual server name \
--image Canonical:UbuntuServer:18.04-LTS:latest \
--admin-username azureuser \
--generate-ssh-keys

Open port (Example: Allow HTTP access to web apps created later)

vm open-port --port 80 \
--resource-group <resource-group-name> \
--name Virtual server name

Get the IP address of the virtual server

ipaddress=$(az vm show \
--name virtual server name \
--resource-group <resource-group-name> \
--show-details \
--query [publicIps] \
--output tsv)

Web App Service

Start Web App Created with Azure App Service

az webapp start --resource-group resource group name \
--name <App Service web app name>

Stop Web App Created with Azure App Service

az webapp stop --resource-group resource group name \
--name <App Service web app name>

 by the author.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.