This article is contributed. See the original author and article here.

The Azure SQL Migration extension for Azure Data Studio provides a seamless and robust migration experience to help you migrate your SQL Server databases to Azure. However, if you have multiple databases across multiple SQL Server instances, migrating them together at scale using graphical UI may not be the most efficient method. Today, we are announcing Public Preview of new migration capabilities added to Az.DataMigration module in Azure PowerShell and az datamigration extension in Azure CLI. With these migration capabilities added to Azure PowerShell and Azure CLI, you can automate tasks and activities related to SQL Server database assessments, performance data collection for Azure recommendations and migration of multiple databases (across multiple SQL Server instances) at scale.


By automating migration activities, you can save time and efficiently migrate a large number of SQL Server databases to Azure SQL Managed Instance or SQL Server on Azure Virtual Machines. For example, the code snippet below demonstrates a SQL Server database migration to Azure SQL Managed Instance using Azure CLI with three commands.


Step 1: Create a new Azure Database Migration service in your Azure subscription.



az datamigration sql-service create --resource-group "myRG" --sql-migration-service-name "myMigrationService" --location "EastUS2"



Step 2: Configure and start online database migration from SQL Server on-premises (with backups in Azure Storage) to Azure SQL Managed Instance.



az datamigration sql-managed-instance create `
--source-location '{"AzureBlob":{"storageAccountResourceId":"/subscriptions/mySubscriptionID/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/dbbackupssqlbits","accountKey":"myAccountKey","blobContainerName":"dbbackups"}}' `
--migration-service "/subscriptions/mySubscriptionID/resourceGroups/myRG/providers/Microsoft.DataMigration/SqlMigrationServices/myMigrationService" `
--scope "/subscriptions/mySubscriptionID/resourceGroups/myRG/providers/Microsoft.Sql/managedInstances/mySQLMI" `
--source-database-name "AdventureWorks2008" `
--source-sql-connection authentication="SqlAuthentication" data-source="mySQLServer" password="myPassword" user-name="sqluser" `
--target-db-name "AdventureWorks2008" `
--resource-group myRG `
--managed-instance-name mySQLMI



Step 3: Perform a migration cutover once all backups are restored to Azure SQL Managed Instance.



$migOpId = az datamigration sql-managed-instance show --managed-instance-name "mySQLMI" --resource-group "myRG" --target-db-name "AdventureWorks2008" --expand=MigrationStatusDetails --query "properties.migrationOperationId"
az datamigration sql-managed-instance cutover --managed-instance-name "mySQLMI" --resource-group "myRG" --target-db-name "AdventureWorks2008" --migration-operation-id $migOpId



Sample scripts to run end-to-end SQL Server database migrations to Azure SQL Managed Instance or SQL Server on Azure Virtual Machines are available in the Azure Samples Github repository (


To learn more, see documentation [Migrate databases at scale using automation]


Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.

%d bloggers like this: