Manage virtual machines with the Azure CLI
Exercise - Create a virtual machine
az vm create
, this will create a VM in a resource group. There are four parameters which must be supplied:
--resource-group: resource group that will own the machine
--name: name of the vm, must be unique within the resource group
--image: OS for the vm
--location: region which to place the VM
Useful to add
--verbose
to see progress while the VM is being created. To automatically return to the commandline use--no-wait
To find help for a specific command, use
--help
.
az vm --help
will provide a list of commands and _subcommands which can be utilized with az vm
.
Exercise - Explore other VM images
The following will provide a list of offline images: az vm image list --output table
will produce a list of available VM images.
We can additionally use az vm image list --output table --all
to provide an up-to-date list. There are filters we can use when viewing this list to try and condense it to certain images we are interested in using.
Available filters:
--publisher
--sku
--offer
Exercise - Query system and runtime information about the VM
Get the list of existing VMs regardless of resource group:
az vm list
Format the results from a command:
az vm list --output table
, default format is jsonadditional options are jsonc (colorized JSON) and tsv (tab seperated values)
Get a list of ip addresses for operational VMs
az vm list-ip-addresses --output table
Add filters to queries with JMESPath
Using JMESPath is a means to filter JSON queries and receive specific data you're looking for, based off an array.
Filters you Azure CLI queries
The query values are case-sensitive
The following will pull the size assigned to the specific VM.
Exercise - Start and stop your VM with the Azure CLI
Stop a VM
Get the power state of the VM:
Resources for review
https://docs.microsoft.com/en-us/cli/azure/
https://docs.microsoft.com/en-us/cli/azure/reference-index