Azure Cli Commands Cheat Sheet



  • Finding commands. Commands in the CLI are organized as commands of groups. Each group represents an Azure service, and commands operate on that service. To search for commands, use az find. For example, to search for command names containing secret, use the following command: az find secret.
  • PowerShell can help you in your studies for the AZ-103, AZ-300 and AZ-301. Tasks can be quickly performed using the command line interface. Skylines has a free PowerShell guide to assist you in your studies. Whether your new to PowerShell or brushing up for the exam, this guide will help ensure y.
  • Finding commands. Commands in the CLI are organized as commands of groups. Each group represents an Azure service, and commands operate on that service. To search for commands, use az find. For example, to search for command names containing secret, use the following command: az find secret.
-->

Welcome to the Azure CLI! This article introduces the CLI and helps you complete common tasks.

Note

This Cheat Sheet provides some reminders of some essential ingredients in Azure automation. Remember to work actively to stay current.

In scripts and on the Microsoft documentation site, Azure CLI examples are written for the bash shell. One-line examples willrun on any platform. Longer examples which include line continuations () or variable assignment need to be modified to workon other shells, including PowerShell.

Install or run in Azure Cloud Shell

The easiest way to get started with the Azure CLI is by running it in an Azure Cloud Shell environment through your browser. To learn about Cloud Shell, see Quickstart for Bash in Azure Cloud Shell.

When you're ready to install the CLI, see the installation instructions.

After installing the CLI for the first time, check that it's installed and you've got the correct version by running az --version.

Note

If you're using the Azure classic deployment model, install the Azure classic CLI.

Sign in

Before using any CLI commands with a local install, you need to sign in with az login.

  1. Run the login command.

    If the CLI can open your default browser, it will do so and load an Azure sign-in page.

    Otherwise, open a browser page at https://aka.ms/devicelogin and enter theauthorization code displayed in your terminal.

    If no web browser is available or the web browser fails to open, use device code flow with az login --use-device-code.

  2. Sign in with your account credentials in the browser.

After logging in, you see a list of subscriptions associated with your Azure account. The subscription information with isDefault: true is the currently activated subscription after logging in. To select another subscription, use the az account set command with the subscription ID to switch to. For more information about subscription selection, see Use multiple Azure subscriptions.

There are ways to sign in non-interactively, which are covered in detail in Sign in with Azure CLI.

Common commands

This table lists some common commands used in the CLI and links to their reference documentation.

Resource typeAzure CLI command group
Resource groupaz group
Virtual machinesaz vm
Storage accountsaz storage account
Key Vaultaz keyvault
Web applicationsaz webapp
SQL databasesaz sql server
CosmosDBaz cosmosdb

Finding commands

Commands in the CLI are organized as commands of groups. Each group represents an Azure service, and commands operate on that service.

To search for commands, use az find. For example, to search for command names containing secret,use the following command:

Use the --help argument to get a complete list of commands and subgroups of a group. For example, to find the CLI commands for working withNetwork Security Groups (NSGs):

The CLI has full tab completion for commands under the bash shell.

Globally available arguments

There are some arguments that are available for every command.

Azure Cheat Sheet Pdf

  • --help prints CLI reference information about commands and their arguments and lists available subgroups andcommands.
  • --output changes the output format. The available output formats are json, jsonc (colorized JSON), tsv (Tab-SeparatedValues), table (human-readable ASCII tables), and yaml. By default the CLI outputs json. To learn more about the availableoutput formats, see Output formats for Azure CLI.
  • --query uses the JMESPath query language to filter the output returned from Azure services. To learn more about queries, see Query command results with Azure CLI and the JMESPath tutorial.
  • --verbose prints information about resources created in Azure during an operation, and other useful information.
  • --debug prints even more information about CLI operations, used for debugging purposes. If you find a bug, provide output generated with the --debug flag on when submitting a bug report.

Interactive mode

The CLI offers an interactive mode that automatically displays help information and makes it easier toselect subcommands. You enter interactive mode with the az interactive command.

For more information on interactive mode, see Azure CLI Interactive Mode.

There's also a Visual Studio Code plugin thatoffers an interactive experience, including autocomplete and mouse-over documentation.

Learn CLI basics with quickstarts and tutorials

To get you started with the Azure CLI, try an in-depth tutorial for setting up virtual machines and using the powerof the CLI to query Azure resources.

There are also quickstarts for other popular services.

Give feedback

We welcome your feedback for the CLI to help us make improvements and resolve bugs. You can file an issue on GitHub or use the built-infeatures of the CLI to leave general feedback with the az feedback command.

See also

Disable Server Affinity

By default, Azure Websites comes preconfigured with Session affinity, which in many cases allows developers perform a very simple migration of their applications to cloud. This is because there is no need to worry about centralizing the session state of your application as a user will be redirected back to the same server on each subsequent request.

Some applications, however, may not require session affinity and it would be better to turn off the session affinity in Azure Websites. This can be achieved by adding the following to the web.config file.

To ensure that the session affinity works during scaling activities, make sure to also add in an AppSetting with the following key value: clientAffinityEnabled = false

Filtering Traffic by IP

Based on your web application, you may want to restrict access to it. Access can be restricted by using the <ipSecurity> element and providing a list of IP address to allow.

If you would like to whitelist azure resources, the Azure Datacenter IP Address Ranges are available online.

The full documentation on the <ipSecurity> element is available on IIS Configuration Reference.

Dynamic IP Restrictions

Dynamic IP Restrictions enable you to block access to your website when based on an interval of requests (i.e. Potential DDoS Attack). This can be achieved in a variety of ways as outlined in the example below.

The full documentation on the <dynamicIpSecurity> element is available on IIS Configuration Reference.

Auto-Heal

You know those bugs where the only way to fix them is to restart the server every so often? There’s a web.config setting for that! Microsoft Azure Websites have the ability to auto-heal based on a number of different triggers, i’ve outlined some of them in the example below. Note that this only works in Standard mode. It throws an error in Free or Basic mode.

HTTP Compression

Some big wins come in small packages, enabling HTTP Compression in your Website can help decrease your users mobile bill and wait time while loading your Web Application.

Azure

Mime Map

It’s possible that you may need to map mime types to IIS if you are going to serve static files.

Cache Control

Enable downstream caching of html for performance and cheaper delivery via Content Delivery Network (CDN). The snippet below enables 1 day, public caching of all HTML content.

Force HTTPS

Enable HTTP Verbs

When building out HTTP based APIs it is nearly impossible to enable functionality without being able to use certain HTTP Verbs such as PUT and DELETE.

.NET

PHP

Enable PUT requests using below web.config and make sure to change PHP Version number

Azure Cli Commands Cheat Sheet

Nodejs

Enable HTTP Strict Transport Security (HSTS)

Azure Cli Commands Cheat Sheet 2020

For more information on HSTS, visit and read this blog post on How to Enable HTTP Strict Transport Security in IIS 7+ by Scott Hanselman.

Remove X-Powered-By Header

Azure Cli Commands Cheat Sheet 2019

The X-Powered-By header typically displays the Language and version information of a website which could be a potential security risk.