This powershell script leverages the Azure CLI to inventory all Azure SQL Databases in your subscription. It organizes the databases by SQL server and resource group, and displays useful details such as service tier, current status, and zone redundancy.
Ideal for cloud administrators, DevOps engineers, or developers managing large-scale Azure environments.
- β Lists all Azure SQL Databases and Azure SQL Managed Instances across your subscription
- π’ Displays the total number of subscriptions scanned
- π Automatically sorts subscriptions alphabetically for consistent output
- ποΈ Groups databases by their parent SQL server and resource group
- π Displays database service tier, status, redundancy type, storage size, failover groups (applicable only to Azure SQL Databases) and compute details in a clean table format
- π Uses standard CLI tools
- π§© Easily customizable for filtering, CSV export
To use this script, you'll need the following installed:
-
Azure CLI
Install instructions -
Login to your Azure account before running the script:
az login
-
β Minimum Role Required To run your script successfully, a user needs at least the Reader role at the subscription level plus visibility into the SQL resources.
Specifically, they need permission to:
- List Azure resources (for az resource list)
- List SQL servers and databases (for az sql db list)
π§ 1. Clone the repository
git clone https://github.com/Azure/azure-sql-db-inventory.git
cd azure-sql-db-inventory
cd scripts
az login
.\list-azure-sql-databases.ps1
- Azure CLI Documentation
- Install Azure CLI
- Azure CLI
az resource list
- Azure CLI
az sql db list
- Azure Built-in Roles: Reader
- Azure Built-in Roles: Contributor
- Azure Role-Based Access Control (RBAC)
If you encounter any issues, here are some common solutions:
-
Error: "Unable to authenticate"
- Ensure you've run
az login
and that you have the necessary permissions for the subscription.
- Ensure you've run
-
Error: "Command not found"
- Make sure you've installed the Azure CLI and are running the script in the correct environment (Bash or PowerShell).
-
Output not as expected
- Ensure your subscription contains SQL databases and that the
az sql db list
command is functioning properly.
- Ensure your subscription contains SQL databases and that the
For more help, refer to the Azure CLI troubleshooting guide.