Resource Group related commands:¶

Listing resource group information:¶

$ az group list (long string of json)
$ az group list | head -15
[
  {
    "id": "/subscriptions/413bdb96-713e-4a35-b648-d61a850402e2/resourceGroups/NetworkWatcherRG",
    "location": "centralus",
    "managedBy": null,
    "name": "NetworkWatcherRG",
    "properties": {
      "provisioningState": "Succeeded"
    },
    "tags": null,
    "type": "Microsoft.Resources/resourceGroups"
  },
  {
    "id": "/subscriptions/413bdb96-713e-4a35-b648-d61a850402e2/resourceGroups/dolrg",
    "location": "centralus",

Listing RG names:¶

$ az group list --query [].name --output tsv
NetworkWatcherRG
dolrg
rg0x001
cloud-shell-storage-eastus
dolkv

Listing RG names and locations:¶

$ az group list --query [].[name,location] --output tsv
NetworkWatcherRG      centralus
dolrg centralus
rg0x001       centralus
cloud-shell-storage-eastus    eastus
dolkv eastus

Listing RG names and locations in table format:¶

$ az group list --query [].[name,location] --output table
Column1                     Column2
--------------------------  ---------
NetworkWatcherRG            centralus
dolrg                       centralus
rg0x001                     centralus
cloud-shell-storage-eastus  eastus
dolkv                       eastus

$ az group list --query "[].{Name:name,Location:location}" --output table
Name                        Location
--------------------------  ----------
NetworkWatcherRG            centralus
dolrg                       centralus
rg0x001                     centralus
cloud-shell-storage-eastus  eastus
dolkv                       eastus

az group list --query "[].{
  Name:name,
  Location:location,
  ID:id}" --output table
Name              Location    ID
----------------  ----------  -----------------------------------------------------------------------------------
rg0x001           centralus   /subscriptions/413bdb96-713e-4a35-b648-d61a850402e2/resourceGroups/rg0x001
NetworkWatcherRG  centralus   /subscriptions/413bdb96-713e-4a35-b648-d61a850402e2/resourceGroups/NetworkWatcherRG

Removing several resource groups:¶

for g in $(az group list --query [].name --output tsv | grep -v rg0x001)
do
  echo az group delete -y --no-wait -g ${g}
  az group delete -y --no-wait -g ${g}
done
az group list --query [].name --output tsv | grep -v rg0x001
az group delete -y --no-wait -g dolrg
az group delete -y --no-wait -g cloud-shell-storage-eastus
az group delete -y --no-wait -g dolkv

Creting a new RG:¶

$ az group create -l centralus --name rg0x002 --tags env=test
{
  "id": "/subscriptions/413bdb96-713e-4a35-b648-d61a850402e2/resourceGroups/rg0x002",
  "location": "centralus",
  "managedBy": null,
  "name": "rg0x002",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": {
    "env": "test"
  },
  "type": "Microsoft.Resources/resourceGroups"
}

OCI

Navigation

  • Cloud related lessons learned
    • AWS:
    • Azure:
  • (Reasonably) current lessons learned:
  • Legacy/archived lessons learned:

Related Topics

  • Documentation overview
    • Cloud related lessons learned
      • Azure lessons learned:
        • Previous: Resource specific azcli commands:
        • Next: roles related azcli commands:

Quick search

©2023, dkoleary. | Powered by Sphinx 7.2.6 & Alabaster 0.7.16 | Page source