Handy az-cli commands

Using Azure REST API with az-cli

az rest -m <method> -u <URI> --body <body> 

where:

  • method: delete, get, head, options, patch, post, put.
  • body: request body.
  • URI URL of the requested resource, and is the only required parameter.

Listing all VM images

# Windows Server
az vm image list --location westeurope --offer WindowsServer --output table

# RHEL
az vm image list --location westeurope --offer RHEL --all --output table |grep RedHat:RHEL # to filter out useless images

Assigning user as a local administrator on VM

Invoke-AzVMRunCommand -Name 'my-vm' -ResourceGroupName 'my-rg' -CommandId 'RunPowerShellScript' -ScriptString { Add-LocalGroupMember -Group Administrators -Member "MY-AD\kasper" }