Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 2.64 KB

File metadata and controls

56 lines (42 loc) · 2.64 KB
title PowerShell: Copy a Database to New Logical Server
description Azure PowerShell example script to copy a database to a new logical server
author WilliamDAssafMSFT
ms.author wiassaf
ms.reviewer wiassaf, mathoma
ms.date 06/10/2025
ms.service azure-sql-database
ms.subservice data-movement
ms.topic sample
ms.custom
sqldbrb=1
devx-track-azurepowershell
ms.devlang powershell

Use PowerShell to copy a database to a new logical server

[!INCLUDEappliesto-sqldb]

This Azure PowerShell script example creates a copy of an existing database in Azure SQL Database in a new logical server.

[!INCLUDE quickstarts-free-trial-note] [!INCLUDE updated-for-az] [!INCLUDE cloud-shell-try-it.md]

If you choose to install and use PowerShell locally, this tutorial requires Az PowerShell 1.4.0 or later. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.

Copy a database to a new logical server

[!code-powershell-interactivemain]

Clean up deployment

Use the following command to remove the resource group and all resources associated with it.

Remove-AzResourceGroup -ResourceGroupName $sourceresourcegroupname
Remove-AzResourceGroup -ResourceGroupName $targetresourcegroupname

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
New-AzResourceGroup Creates a resource group in which all resources are stored.
New-AzSqlServer Creates a new logical server that hosts databases and elastic pools.
New-AzSqlDatabase Creates a database or elastic pool.
New-AzSqlDatabaseCopy Creates a copy of a database that uses the snapshot at the current time.
Remove-AzResourceGroup Deletes a resource group including all nested resources.

Related content