Tutorial: Install the SQL, IIS, .NET stack in a Windows VM with Azure PowerShell

In this tutorial, we install a SQL, IIS, .NET stack using Azure PowerShell. This stack consists of two VMs running Windows Server 2016, one with IIS and .NET and the other with SQL Server.

  • Create a VM
  • Install IIS and the .NET Core SDK on the VM
  • Create a VM running SQL Server
  • Install the SQL Server extension

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.

To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to https://shell.azure.com/powershell. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press enter to run it.

Create an IIS VM

In this example, we use New-AzVM cmdlet in the PowerShell Cloud Shell to quickly create a Windows Server 2016 VM and then install IIS and the .NET Framework. The IIS and SQL VMs share a resource group and virtual network, so we create variables for those names.

$vmName = "IISVM"
$vNetName = "myIISSQLvNet"
$resourceGroup = "myIISSQLGroup"
New-AzVm `
    -ResourceGroupName $resourceGroup `
    -Name $vmName `
    -Location "East US" `
    -VirtualNetworkName $vNetName `
    -SubnetName "myIISSubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
	-AddressPrefix 192.168.0.0/16 `
    -PublicIpAddressName "myIISPublicIpAddress" `
    -OpenPorts 80,3389 

Install IIS and the .NET framework using the custom script extension with the Set-AzVMExtension cmdlet.

Set-AzVMExtension `
    -ResourceGroupName $resourceGroup `
    -ExtensionName IIS `
    -VMName $vmName `
    -Publisher Microsoft.Compute `
    -ExtensionType CustomScriptExtension `
    -TypeHandlerVersion 1.4 `
    -SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server,Web-Asp-Net45,NET-Framework-Features"}' `
    -Location EastUS

Create another subnet

Create a second subnet for the SQL VM. Get the vNet using [Get-AzVirtualNetwork]{/powershell/module/az.network/get-azvirtualnetwork}.

$vNet = Get-AzVirtualNetwork `
   -Name $vNetName `
   -ResourceGroupName $resourceGroup

Create a configuration for the subnet using Add-AzVirtualNetworkSubnetConfig.

Add-AzVirtualNetworkSubnetConfig `
   -AddressPrefix 192.168.0.0/24 `
   -Name mySQLSubnet `
   -VirtualNetwork $vNet `
   -ServiceEndpoint Microsoft.Sql

Update the vNet with the new subnet information using Set-AzVirtualNetwork

$vNet | Set-AzVirtualNetwork

Azure SQL VM

Use a pre-configured Azure marketplace image of a SQL server to create the SQL VM. We first create the VM, then we install the SQL Server Extension on the VM.

New-AzVm `
    -ResourceGroupName $resourceGroup `
    -Name "mySQLVM" `
	-ImageName "MicrosoftSQLServer:SQL2016SP1-WS2016:Enterprise:latest" `
    -Location eastus `
    -VirtualNetworkName $vNetName `
    -SubnetName "mySQLSubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "mySQLPublicIpAddress" `
    -OpenPorts 3389,1401 

Use Set-AzVMSqlServerExtension to add the SQL Server extension to the SQL VM.

Set-AzVMSqlServerExtension `
   -ResourceGroupName $resourceGroup  `
   -VMName mySQLVM `
   -Name "SQLExtension" `
   -Location "EastUS"

Next steps

In this tutorial, you installed a SQL\IIS\.NET stack using Azure PowerShell. You learned how to:

  • Create a VM
  • Install IIS and the .NET Core SDK on the VM
  • Create a VM running SQL Server
  • Install the SQL Server extension

Advance to the next tutorial to learn how to secure IIS web server with SSL certificates.