Friday, May 13, 2022

PowerShell scripts for exporting an Azure subscription's Azure SQL Databases to an Excel file and using the updated Excel file to export/backup the databases

I’ve recently been involved in a manual migration of multiple subscriptions from a tenant to another due to an organization change and one of the components that I was responsible for was the migration of the Azure SQL Databases. I had originally hoped that I would be able to use the DMA (Data Migration Assistant) but attempting to select an Azure SQL Database as a source would throw an error indicating it was not supported. Given that there weren’t too many databases and there were only 2 that would require an outage, we decided that we’ll perform an export/backup of the databases to a storage account and then import/restore them in the destination subscription.

While it is possible to manually export them via the GUI:


A more efficient way was to use PowerShell to export all of the subscription’s databases and its properties into an Excel file, update the Excel file with the SQL credentials, then use PowerShell to read through the Excel spreadsheet to export/backup the databases to a Storage account.

The PowerShell script I created that will export all of a subscription’s Azure SQL Database properties can be found here:

The following screenshot is an example of the export:


Assuming that each database has different credentials, add the additional columns to store the SQL Authentication username and password:

  • Username
  • Password

With the spreadsheet updated, we can now use this PowerShell script export/backup all of a subscription’s Azure SQL Database to a storage account container:

Hope this helps anyone who might be looking for a way to automate the process of exporting a subscription’s Azure SQL Database to Excel and then using the list to backup the databases.

No comments: