Azure CLI
Auth
- azure login
az login # open brewser to login
az login -u <username> -p <password> # usename and password login
az login --tenant <tenant> # use different tenant login
- switch tenant
az account list --output table # list accounts as table
az account set --subscription "Wilson" # switch others subscriptions
VM
- vm list
List details of Virtual Machines
az vm list --output table # list virtual machines as table
az vm list --output table -d # list virtual machines details as table
az vm list -g ResourceGroup --output table # list virtual machines of ResourceGroup as table
- vm create
Create an Azure Virtual Machine
az vm create -n vm_name -g resource_group --image UbuntuLTS # Create a default Ubuntu VM
az vm create -n vm_name -g resource_group --image my_image # Create a VM from a custom managed image
az vm create -n vm_name -g resource_group --image centos --count 3 # Create multiple VMs(vm_name1, vm_name2, vm_name3)
- az vm restart
Restart a VM.
az vm restart -n vm_name -g resource_group # Restart a VM
az vm restart --ids $(az vm list -g resource_group --query "[].id" -o tsv) # Restart all VMs in a resource group
- az vm update
Update the properties of a VM.
az vm update -n vm_name -g resource_group --set tags.tagName=tag_name # Add or update a tag
az vm update -n vm_name -g resource_group --remove tags.tagName # Remove a tag
- az vm resize
Update a VM's size.
az vm resize -n vm_name -g resource_group --size Standard_DS3_v2 # Resize a VM
az vm resize --size Standard_DS3_v2 --ids $(az vm list -g resource_group --query "[].id" -o tsv) # Resize all VMs in a resource group
- az vm start
Start a stopped VM
az vm start -n vm_name -g resource_group # Start a stopped VM.
az vm start --ids $(az vm list -g resource_group --query "[].id" -o tsv) # Start all VMs in a resource group
- az vm stop
Power off (stop) a running VM.
az vm stop -n vm_name -g resource_group # Power off (stop) a running VM
az vm stop -n vm_name -g resource_group --skip-shutdown # Power off a running VM without shutting down.
az vm stop --ids $(az vm list -g resource_group --query "[].id" -o tsv) # Power off VMs in a resource group
- az vm delete
Delete a VM.
az vm delete -n vm_name -g resource_group --yes # Delete a VM without a prompt for confirmation
az vm delete --ids $(az vm list -g resource_group --query "[].id" -o tsv) # Delete all VMs in a resource group
az webapp
- az webapp browse
Open a web app in a browser.
az webapp browse -n app_name -g resource_group # Open a web app in a browser
- az webapp create
Create a web app.
az webapp create -n app_name -g resource_group -p plan # Create a web app with the default configuration.
az webapp create -n app_name -g resource_group -p plan --runtime "java|11|Java SE|8" # Create a web app with a java|11|Java SE|8 runtime using '|' delimiter
az webapp create -n app_name -g resource_group -p plan -i image_name -s username -w password # Create a web app with an image from a private DockerHub registry.
az webapp create -n app_name -g resource_group -p plan -i myregistry.azurecr.io/docker-image:tag # Create a web app with an image from a private Azure Container Registry.
- az webapp list
List web apps.
az webapp list --query "[?state=='Running']" # List all running web apps.
az webapp list --query "[].{hostName: defaultHostName, state: state}" # List default host name and state for all web apps.
- az webapp show
Get the details of a web app.
az webapp show -n app_name -g resource_group # Get the details of a web app. (autogenerated)
az webapp show -n app_name -g resource_group --output table # List the details of table format
- az webapp ssh
SSH into a web app. (Only Linux App Service Plans supported)
az webapp ssh -n app_name -g resource_group # ssh into a web app
- az webapp start
Start a web app.
az webapp start -n app_name -g resource_group # Start a web app. (autogenerated)
- az webapp stop
Stop a web app.
az webapp stop -n app_name -g resource_group # Stop a web app. (autogenerated)
- az webapp update
Update a web app.
az webapp update -n app_name -g resource_group --set tags.tagName=tagValue # Update the tags of a web app.
az webapp update --https-only true -n app_name -g resource_group # Update a web app. (autogenerated)
- az webapp delete
Delete a web app.
az webapp delete -n app_name -g resource_group # Delete a web app. (autogenerated)