Quantcast
Channel: SQL Database Engine Blog
Viewing all articles
Browse latest Browse all 168

Quick-start script: Create Azure SQL Managed Instance using PowerShell

$
0
0

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.

As a prerequisite, you would need to create VNET/subnet using setup quick start script and use the names of vNet, subnet, and resource group that you configured in that script. Make sure that you have installed Azure RM PowerShell .

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 SQL Server licence


# Setup subscription specific information
Select-AzureRmSubscription -Subscription $subscriptionId 
$vNet = Get-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $resourceGroup
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $vNet
$subnetId = $subnet.Id

$properties = New-Object System.Object
$properties | Add-Member -type NoteProperty -name subnetId -Value $subnet.Id
$sku = @{ tier="GeneralPurpose"; name="GP_Gen4"} #or GP_Gen5


$properties | Add-Member -type NoteProperty -name administratorLogin -Value $miAdminSqlLogin
$properties | Add-Member -type NoteProperty -name administratorLoginPassword -Value $miAdminSqlPassword
$properties | Add-Member -type NoteProperty -name vCores -Value $vCores
$properties | Add-Member -type NoteProperty -name storageSizeInGB -Value $maxStorage
$properties | Add-Member -type NoteProperty -name licenseType -Value $license

New-AzureRmResource -Location $location `
                    -Sku $sku `
                    -Properties $properties `
                    -ResourceName $instanceName `
                    -ResourceType "Microsoft.SQL/managedInstances" `
                    -ResourceGroupName $resourceGroup `
                    -Force -ApiVersion "2015-05-01-preview"


 


Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>