Azure PowerShell samples for Azure SQL Managed Instance
Applies to: Azure SQL Managed Instance
Azure SQL Managed Instance enables you to configure your instances, and pools by using Azure PowerShell.
If you don't have an Azure subscription, create an Azure free account before you begin.
Use Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.
To start Azure Cloud Shell:
Option | Example/Link |
---|---|
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell. | |
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. | |
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. |
To run the code in this article in Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block to copy the code.
Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.
Select Enter to run the code.
If you choose to install and use the 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.
Samples
The following table includes links to sample Azure PowerShell scripts for Azure SQL Managed Instance.
Link | Description |
---|---|
Create and configure managed instances | |
Create and manage a managed instance | This PowerShell script shows you how to create and manage a managed instance using Azure PowerShell. |
Create and manage a managed instance using the Azure Resource Manager template | This PowerShell script shows you how to create and manage a managed instance using Azure PowerShell and the Azure Resource Manager template. |
Restore database to a managed instance in another geo-region | This PowerShell script takes a backup of one database and restores it to another region. This is known as a geo-restore disaster-recovery scenario. |
Configure transparent data encryption | |
Manage transparent data encryption in a managed instance using your own key from Azure Key Vault | This PowerShell script configures transparent data encryption in a Bring Your Own Key scenario for Azure SQL Managed Instance, using a key from Azure Key Vault. |
Configure a failover group | |
Configure a failover group for a managed instance | This PowerShell script creates two managed instances, adds them to a failover group, and then tests failover from the primary managed instance to the secondary managed instance. |
Learn more about PowerShell cmdlets for Azure SQL Managed Instance.
Related content
The examples listed on this page use az.sql PowerShell cmdlets for creating and managing Azure SQL resources. Additional cmdlets for running queries and performing many database tasks are located in the SqlServer PowerShell cmdlets. For more information, see SQL Server PowerShell.