I need to list the Azure SQL servers in an Azure account for all subscriptions. I need to list them for all subscriptions in one call or is there any other way to achieve this like using script for the Azure account other than API calls? Please help. It would be really helpful if the script is also provided.
I know this is possible, using Azure rest API, but we could list it only for one subscription at a time. But I am expecting to have the response for all subscriptions at the same time.
Thanks @Peter Bons for the comment.
Yes, you can check the results in Resource Graph Explorer.
If you want to go with CloudShell, check the below Bash script to get the list of SQL resources.
Open the Azure Cloud Shell
,
You need to have read permissions on other subscriptions to list the resources.
In Bash, run the below command to get the list of SQL query
az sql server list
sub_ids=$(az account list --all --query '[].id' -o tsv)
sub_ids=$(az account list --all --query '[].id' -o tsv)
for sub_id in $sub_ids;
do
echo "List of SQL Servers for Subscription ID: $sub_id"
az sql server list --subscription $sub_id --query '[].{SQLServer: name, ResourceGroup: resourceGroup, Location: location}' --output table
done
Output:
As I don't have authorization on other subscription, Iam getting the below error.
Make sure you have required permissions to read other subscriptions.