Change size of Azure SQL Managed Instance using PowerShell

Azure SQL Managed Instance is fully-managed SQL Server Database Engine hosted in Azure cloud. With Managed Instance you can easily add/remove cores associated to the instance and change the reserved size of the instance. You can use PowerShell to easily manage size of the instance and automate this process.

As a prerequisite, you need to have Azure SQL PowerShell libraries to configure Managed Instance. You would need to install Azure RM PowerShell and  AzureRm.Sql module that contains the commands for updating properties of Managed Instance.

In most of the cases, the following three commands might install everything that you need:

Install-Module PowerShellGet -Force
Install-Module -Name AzureRM -AllowClobber
Install-Module -Name AzureRM.Sql -AllowPrerelease -Force

You would need at least version 1.6.0 of PowerShellGet because AzureRm.Sql is in pre-release and -AllowPrerelease switch is required to discover it.

In some cases this version would not be loaded, so you would need to run something like:

Import-PackageProvider -Name PowerShellGet -Force -RequiredVersion 1.6.0

Sometime you might have version collision with the current version of PowerShellGet, so you might need to uninstall previous version (note that old version might be installed in Program Files, Program Files (x86) or both places so if you try to physically delete is it might be referenced on another place).

Then, you need to run something like the following PowerShell script :

Connect-AzureRmAccount

$subId = "8cmb8b62-bed6-4713-89ad-18497f75af51"
$resourceGroup = "my_managed_instances"
$instanceName = "jovanpop-managed-instance-gp"

Select-AzureRmSubscription -SubscriptionId $subId

$vCores = 16
$size = 512
Update-AzureRmSqlManagedInstance `
               -Name $instanceName `
               -ResourceGroupName $resourceGroup `
               -VCore $vCores `
               -StorageSizeInGB $size

In this example, after connecting to my azure account, I’m selecting the subscription where my managed instance jovanpop-managed-instance-gp is placed and setting resource group name.

Then, I need to execute command Update-AzureRmSqlManagedInstance from AzureRm.Sql module, provide instance name and resource group where the instance is placed, and number of vCores and max storage size for the instance. You don’t need to specify both values – you can change just number of cores or just max storage size limit.

The change that you made might break connection to your instance because the instance might be moved to the new location. If you are implementing retry-logic in your data access code you don’t need to stop your workload while Managed Instance is changing the resources. You can continue running your workload while the change is happening.

You can update other properties of Azure SQL Managed Instance using this command. Syntax of the command is shown below (description can be found with command

man Update-AzureRmSqlManagedInstance

):

 Update-AzureRmSqlManagedInstance [-InputObject] <AzureSqlManagedInstanceModel> [-AdministratorPassword
 <SecureString>] [-AssignIdentity] [-DefaultProfile <IAzureContextContainer>] [-Force] [-LicenseType <String>]
 [-StorageSizeInGB <Int32>] [-Tag <Hashtable>] [-VCore <Int32>] [-Confirm] [-WhatIf] [<CommonParameters>]