How to use the command 'az' (with examples)

How to use the command 'az' (with examples)

The ‘az’ command is the official CLI tool for Microsoft Azure. It provides a wide range of functionalities for managing Azure resources and services. This article will explore different use cases of the ‘az’ command and provide examples for each use case.

Use case 1: Log in to Azure

Code:

az login

Motivation: The ‘az login’ command is used to authenticate and log in to an Azure account. It is necessary to authenticate before performing any operations on Azure resources.

Explanation: The ‘az login’ command does not require any arguments. When executed, it will open a browser window for the user to sign in to their Azure account. Once the user has successfully authenticated, the command will return a session token that can be used for subsequent Azure operations.

Example output:

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCDEFGHI to authenticate.
[
  {
    "cloudName": "AzureCloud",
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "isDefault": true,
    "name": "My Azure Account",
    "state": "Enabled",
    "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "user": {
      "name": "john.doe@microsoft.com",
      "type": "user"
    }
  }
]

Use case 2: Manage Azure subscription information

Code:

az account

Motivation: Once logged in to Azure, the ‘az account’ command allows you to manage and view information about your Azure subscriptions.

Explanation: The ‘az account’ command without any arguments will display information about the currently logged-in account, including the subscription name, ID, associated tenant ID, and the user’s email address.

Example output:

[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "isDefault": true,
    "managedByTenants": [],
    "name": "My Azure Account",
    "state": "Enabled",
    "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "user": {
      "name": "john.doe@microsoft.com",
      "type": "user"
    }
  }
]

Use case 3: List all Azure Managed Disks

Code:

az disk list

Motivation: The ‘az disk list’ command allows you to retrieve a list of all Azure Managed Disks in your subscription. This information can be useful for monitoring and managing the disks in your Azure environment.

Explanation: The ‘az disk list’ command without any arguments will retrieve information about all Azure Managed Disks in the current subscription. This includes details such as disk name, ID, resource group, and disk size.

Example output:

[
  {
    "creationData": {
      "createOption": "Empty"
    },
    "diskSizeGb": 32,
    "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myDisk",
    "location": "eastus",
    "name": "myDisk",
    "osType": null,
    "resourceGroup": "myResourceGroup",
    "sku": {
      "name": "Premium_LRS",
      "tier": "Premium"
    },
    "zones": null
  },
  ...
]

Use case 4: List all Azure virtual machines

Code:

az vm list

Motivation: The ‘az vm list’ command is used to retrieve a list of all Azure virtual machines in your subscription. This can be helpful for monitoring and managing the virtual machines in your Azure environment.

Explanation: The ‘az vm list’ command without any arguments will retrieve information about all Azure virtual machines in the current subscription. This includes details such as VM name, ID, resource group, VM size, and VM status.

Example output:

[
  {
    "diagnosticsProfile": null,
    "hardwareProfile": {
      "vmSize": "Standard_DS2_v2"
    },
    "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
    "location": "eastus",
    "name": "myVM",
    "networkProfile": null,
    "osProfile": null,
    "provisioningState": "Succeeded",
    "resourceGroup": "myResourceGroup",
    "storageProfile": null
  },
  ...
]

Use case 5: Manage Azure Kubernetes Services

Code:

az aks

Motivation: The ‘az aks’ command is used to manage Azure Kubernetes Services (AKS). This allows you to create, update, or delete AKS clusters, as well as perform other operations related to AKS.

Explanation: The ‘az aks’ command provides several subcommands for managing AKS clusters. For example, you can use ‘az aks create’ to create a new AKS cluster, ‘az aks update’ to update an existing cluster, and ‘az aks delete’ to delete a cluster. Each subcommand has its own set of arguments and options.

Example output: Not applicable as the output depends on the specific subcommand used with ‘az aks’.

Use case 6: Manage Azure Network resources

Code:

az network

Motivation: The ‘az network’ command is used to manage Azure Network resources. This includes operations such as creating and configuring virtual networks, subnets, network security groups, and more.

Explanation: The ‘az network’ command provides several subcommands for managing different Azure network resources. For example, you can use ‘az network vnet create’ to create a new virtual network, ‘az network nsg list’ to list all network security groups, and ‘az network subnet delete’ to delete a subnet. Each subcommand has its own set of arguments and options.

Example output: Not applicable as the output depends on the specific subcommand used with ‘az network’.

Conclusion:

The ‘az’ command is a versatile and powerful CLI tool for managing Microsoft Azure resources. It provides a wide range of functionalities for managing various Azure services and resources. By understanding and utilizing the different subcommands of the ‘az’ command, users can effectively manage and monitor their Azure environment.

Related Posts

How to use the command ctags (with examples)

How to use the command ctags (with examples)

The ctags command is used to generate an index (or tag) file of language objects found in source files for many popular programming languages.

Read More
How to use the command transmission-show (with examples)

How to use the command transmission-show (with examples)

Transmission-show is a command-line utility that provides information about torrent files.

Read More
How to use the command 'tb' (with examples)

How to use the command 'tb' (with examples)

The ’tb’ command is a tool for managing tasks and notes across multiple boards.

Read More