First published on MSDN on Jun 27, 2018
Azure SQL Database Managed Instance is a fully managed SQL Server Database Engine hosted in Azure cloud. In this post you can find a simple PowerShell script that you can use to quickly create a new Managed Instance.
Once you install everything and prepare environment, you can run the following script to create a Managed Instance. You just need to change the following parameters in the script below:
Environment where Managed Instance should be placed - Azure subscription id, VNET/subnet name, and resource group.
Managed Instance properties - sql login/password used to connect to the instance, size of the instance (cores/max storage)
The following script creates new Managed Instance in your Azure network:
# Set parameters
$subscriptionId = "b4c5a924-14c1-4bde-e7b170769m3"
$resourceGroup = "..."
$location = "West Central US"
$vNetName = "..."
$subnetName = "..."
$instanceName = "myManagedInstance"
$miAdminSqlLogin = "mysqlloginname"
$miAdminSqlPassword = "some strong password"
$vCores = 16
$maxStorage = 256
$license = "BasePrice" # or LicenseIncluded if you have don't have SQL Server licence that can be used for AHB discount
Instead of the core Azure.RM PowerShell library you can use Azure.Rm.Sql library that have commands specialized for Azure SQL Database. In this case, you would use
command as shown in the following example: