Automation script for list out all resources

Regular Visitor

Hi all,

 

This script will help you to list out all resources under you subscriptions.
It's fully automation, in a single click you can get all resources details in you environment.

How it's working:

  • getting all subscription details,
  • getting all resource group details under your subscription
  • list out all resources one by one

---------------------------------------------------------------------------------------------------------------

Automation Script:

#Get Subscription count
subcount=$(az account list --query [].name |jq '. |length')

num=0
while [ $num -lt $subcount ]
do
#Getting Subscription ID
subname=$(az account list --query [${num}].id -o tsv)
#Getting Subscription Name
subname1=$(az account list --query [${num}].name -o tsv)
#setting up Subscription
az account set --subscription $subname
echo "$subname1"
#Getting Resource Group count
count=$(az group list --subscription $subname --query [].name | jq '. | length')
number=0
while [ $number -lt $count ]

do
#Getting Resource Group Name
name=$(az group list --subscription $subname --query [${number}].name -o tsv)

echo "
Resource Group Name= $name
"
#list out all resources
az resource list --resource-group $name --query "[].{ResourceName:name, Type:type,CreationDate:createdTime}" --output table

number=$(( number+1))
done

num=$((num+1))

done

---------------------------------------------------------------------------------------------------------------

Sample Output:

Subscription name XXXXXXXXXXXXXXXXX

Resource Group name XXXXXXXXXXXXX

Resource Name Type CreationDate
xxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx


Resource Group Name XXXXXXXXXXXX

Resource Name Type CreationDate
xxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx

 

 

Hope this will help, more query please ping me.

0 Replies