Skip to content

Azure Commands

VM realted

# Get a list of subscriptions for the logged in account. (autogenerated)
az account list 

az vm list

az group list --query "[?location=='eastus2']"  

NSG

# get the nsg associated with an RG
az network nsg list \
  --resource-group XXX \
  --query '[].name' \
  --output tsv

Get NSG rules

az network nsg rule list \
  --resource-group XXX \
  --nsg-name my-vmNSG

Create a NSG rule

Here we are creaating a rule to allow the http access on port 80

az network nsg rule create \
  --resource-group XXX \
  --nsg-name my-vmNSG \
  --name allow-http \
  --protocol tcp \
  --priority 100 \
  --destination-port-range 80 \
  --access Allow

Check if rule is added

az network nsg rule list \
    --resource-group XXX \
    --nsg-name my-vmNSG  \
    --query '[].{Name:name, Priority:priority, Port:destinationPortRange, Access:access}'  \
    --output table


Name               Priority    Port    Access
-----------------  ----------  ------  --------
default-allow-ssh  1000        22      Allow
allow-http         100         80      Allow

Was this page helpful?
-->